first of all, i am from germany and still in school so sorry for my poor english. I am trying to make a 2D Plattformer for Android, using Libgdx, Box2d and Tiled, and everything worked fine till began to work on stuff that the player could collect(coins and hearts). I placed circle objects in tiled and made the bodies and fixtures in eclipse. At contact i add the particular body to an array and after a worldstep i check the array, if it contains a body it will be destroyed and the array cleared. My problem now is that after a really short amount of time where the runs as it is supposed to, it will just freeze. But if i run the desktopversion it doesn't freeze(testet it for a while). I searched on the internet for similar problems but solutions to them didn't help me, so i decided to register myself on this site where i am normally finding my answers. I added all code that i think could have something to do with this and also all of my error messages.
My play screen
public Test(MyGame game,int state ,Content content) {
super(game,state);
this.content = content;
Gdx.input.setInputProcessor(inputProcessor = new MyInputProcessor());
world = new World(new Vector2(0, -5.81f), true);
cl = new MyContactListener(this);
world.setContactListener(cl);
b2dr = new Box2DDebugRenderer();
b2dCam = new OrthographicCamera();
b2dCam.setToOrtho(false, MyGame.WIDTH / PPM, MyGame.HEIGHT / PPM);
jumpButton= new Rectangle(hudCam.viewportWidth/8*3 ,-hudCam.viewportHeight/2,hudCam.viewportWidth/8,hudCam.viewportWidth/8);
leftButton= new Rectangle(-hudCam.viewportWidth/2,-hudCam.viewportHeight/2,hudCam.viewportWidth/8,hudCam.viewportWidth/8);
rightButton= new Rectangle(-hudCam.viewportWidth/8*3,-hudCam.viewportHeight/2,hudCam.viewportWidth/8,hudCam.viewportWidth/8);
pauseButton= new Rectangle(hudCam.viewportWidth/8*3 ,hudCam.viewportHeight/2-hudCam.viewportWidth/8,hudCam.viewportWidth/8,hudCam.viewportWidth/8);
menuButton = new Rectangle(hudCam.viewportWidth/12,-hudCam.viewportHeight/16*3,hudCam.viewportWidth/12*3,hudCam.viewportWidth/8);
againButton = new Rectangle(-hudCam.viewportWidth/6*2,-hudCam.viewportHeight/16*3,hudCam.viewportWidth/12*3,hudCam.viewportWidth/8);
createMap();
createWorldBoxes();
createPlayer();
createCollectible();
public void update(float delta) {
xsp=player.getBody().getLinearVelocity().x;
handleInput();
world.step(Gdx.graphics.getDeltaTime(), 1, 1);
//remove coinBodies
Array<Body> bodies = cl.getCoinBodies();
for(int i = 0; i < bodies.size; i++) {
if(bodies.get(i) != null){
Body b = bodies.get(i);
coins.removeValue((Coin)b.getUserData(), true);
world.destroyBody(bodies.get(i));
// add coin value
//play sound
}
}
bodies.clear();
//remove heartBodies
bodies = cl.getHeartBodies();
for(int i = 0; i < bodies.size; i++) {
if(bodies.get(i) != null){
Body b = bodies.get(i);
hearts.removeValue((Heart)b.getUserData(), true);
world.destroyBody(bodies.get(i));
player.increaseLife(1);
// player.collectCrystal(); add coin value
//play sound
}
}
bodies.clear();
//delete collected things, increase live(decrease life)
player.update(Gdx.graphics.getDeltaTime());
for(int i = 0; i < coins.size; i++) {
coins.get(i).update(delta);
}
for(int i = 0; i < hearts.size; i++) {
hearts.get(i).update(delta);
}
}
I skipped some things the render method for example.
My contactlistener
public class BBContactListener implements ContactListener {
private int numFootContacts;
private Array<Body> bodiesToRemove;
private boolean playerDead;
public BBContactListener() {
super();
bodiesToRemove = new Array<Body>();
}
public void beginContact(Contact contact) {
Fixture fa = contact.getFixtureA();
Fixture fb = contact.getFixtureB();
if(fa == null || fb == null) return;
if(fa.getUserData() != null && fa.getUserData().equals("foot")) {
numFootContacts++;
}
if(fb.getUserData() != null && fb.getUserData().equals("foot")) {
numFootContacts++;
}
if(fa.getUserData() != null && fa.getUserData().equals("crystal")) {
bodiesToRemove.add(fa.getBody());
}
if(fb.getUserData() != null && fb.getUserData().equals("crystal")) {
bodiesToRemove.add(fb.getBody());
}
if(fa.getUserData() != null && fa.getUserData().equals("spike")) {
playerDead = true;
}
if(fb.getUserData() != null && fb.getUserData().equals("spike")) {
playerDead = true;
}
}
public void endContact(Contact contact) {
Fixture fa = contact.getFixtureA();
Fixture fb = contact.getFixtureB();
if(fa == null || fb == null) return;
if(fa.getUserData() != null && fa.getUserData().equals("foot")) {
numFootContacts--;
}
if(fb.getUserData() != null && fb.getUserData().equals("foot")) {
numFootContacts--;
}
}
public boolean playerCanJump() { return numFootContacts > 0; }
public Array<Body> getBodies() { return bodiesToRemove; }
public boolean isPlayerDead() { return playerDead; }
public void preSolve(Contact c, Manifold m) {}
public void postSolve(Contact c, ContactImpulse ci) {}
}
I get lots of these errors.
06-09 03:24:05.268: E/Trace(19264): error opening trace file: No such file or directory (2)
Of these too.
06-09 03:23:26.126: E/Crashlytics(19117): Crashlytics must be initialized by calling Crashlytics.start(Context) prior to logging messages.
also different ones of these "could not find class" errors.
06-09 03:22:04.549: E/dalvikvm(19002): Could not find class 'android.app.Notification$Action$Builder', referenced from method b.a
Some sensor errors
06-09 03:16:49.172: E/Sensors(617): Error while trying to enable 9 axis sensor fusion : 22
I get these even if the game freezes
06-09 03:29:21.615: E/overlay(263): [HWC] handleEvent: state changed OV_BYPASS_3_LAYER-->OV_CLOSED 06-09 03:30:27.516: E/overlay(263): [HWC] handleEvent: state changed OV_CLOSED-->OV_BYPASS_3_LAYER
i just remembered that i changed the project compliance and jre to 1.7 so i could use the switch statement with strings.
i hope this is enough information but in case you need could need more let just let me know.
thank you for reading and hopefully answering too.