Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I didn't find any answer to my problem so far. Each i launch my game, the JVM gave me this error:

Error :(

The idea is to create new object on the screen by creating new body with Box2D. So i create the class "loopCreateWeapon":

public class LoopCreateEnnemy {

private boolean isActive;
private BoxObjectManager boxObjectManager;
private Random r;
private float compteur;
private int lastTime;

public LoopCreateEnnemy(BoxObjectManager boxObjectManager) {

    this.boxObjectManager=boxObjectManager;
    r = new Random();
    isActive=true;
    compteur=0;
    lastTime=-1;

}

public void update(float dt){

    compteur += dt;
    int compteurInt = (int) compteur;

    if(isActive){

        int mod = compteurInt%5;

        if(lastTime!=compteurInt && mod==0){

            int height= r.nextInt(GlobalSettings.VIRTUAL_HEIGHT);


            System.out.println(lastTime +" - "+ compteurInt);


                Weapon weapon = new Weapon(boxObjectManager.getNewObjectIndex(), 1, new Vector2(50,height));
                weapon.setDensity(1f);
                weapon.setRestitution(0f);

                boxObjectManager.addObject(weapon);

        }
    }

    lastTime=compteurInt;

}

}

(For explanation, i try to create a Weapon each second) I call the update method in the update method of my Screen class that implement the LoopCreateEnnemy.

I hope you'll be able to help me. I'm stuck with this situation.

Thanks !

share|improve this question
1  
Why is Microsoft Visual C++ giving you errors for Java? –  TheNickmaster21 Oct 6 at 0:30
 
@TheNickmaster21 Likely because the Box2D library is a Microsoft Visual C++ library. –  Byte56 Oct 6 at 0:33
 
Is it Java compatible? –  TheNickmaster21 Oct 6 at 0:34
 
It has a Java wrapper, so yes. –  Byte56 Oct 6 at 0:36

1 Answer

It seems that this issue arises when you try to create too many body objects that are overlapping (if it detects overlapping bounds it will reset their positions). My solution is to ensure that your bodies never overlap upon creation. You should check that the gap between the values on the VIRTUAL_HEIGHT is larger that your weapon's body height and width. Hope that helps.

share|improve this answer
 
Do you have a reference for too many overlapping bodies being the cause of this issue, or is this just anecdotal? –  ktodisco Nov 15 at 22:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.