首先,我来自德国,仍然在学校,对我可怜的英语感到抱歉。 我正在尝试使用Libgdx,Box2d和Tiled为Android制作2D Plattformer,一切正常,直到开始处理玩家可以收集的东西(硬币和心脏)。我将圆形物体放置在平铺中,并在日食中制作了物体和固定装置。在联系我时,将特定的主体添加到一个数组中,在一个世界步骤之后我检查数组,如果它包含一个主体,它将被销毁并清除数组。我现在的问题是,经过一段非常短的时间运行,它将会冻结。但是,如果我运行desktopversion它不会冻结(测试它一段时间)。我在互联网上搜索类似的问题,但他们的解决方案对我没有帮助,所以我决定在这个网站上注册,我通常会找到答案。 我添加了所有可能与此有关的代码以及我的所有错误消息。
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);
}
}
我跳过了渲染方法的一些例子。
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) {}
}
我收到很多这些错误。
06-09 03:24:05.268:E / Trace(19264):错误打开跟踪文件:没有这样的文件或目录(2)
其中也是。
06-09 03:23:26.126:E / Crashlytics(19117):必须在记录消息之前通过调用Crashlytics.start(Context)来初始化Crashlytics。
这些“找不到类”错误也不同。
06-09 03:22:04.549:E / dalvikvm(19002):找不到类'android.app.Notification $ Action $ Builder',引自方法b.a
一些传感器错误
06-09 03:16:49.172:E / Sensors(617):尝试启用9轴传感器融合时出错:22
即使游戏冻结我也会得到这些
06-09 03:29:21.615:E / overlay(263):[HWC] handleEvent:状态已更改OV_BYPASS_3_LAYER - &gt; OV_CLOSED 06-09 03:30:27.516:E / overlay(263):[HWC] handleEvent:状态已更改OV_CLOSED - &gt; OV_BYPASS_3_LAYER
我只记得我将项目合规性和jre更改为1.7,因此我可以将switch语句与字符串一起使用。
我希望这是足够的信息,但如果您需要更多,请告诉我。
感谢您的阅读,也希望能够回答。