In my almost finished game I want to set a new screen on game over. I got my game over method:
private void gameOver(Label score) {
for (Body body : worldBodies) {
world.destroyBody(body);
}
dispose();
((Game) Gdx.app.getApplicationListener()).setScreen(new GameOver());
}
Whenever the method gets called the screen freezes for a second and the game crashes with this statement:
JNI DETECTED ERROR IN APPLICATION
09-02 22:04:34.036 391-425/com.joelbrun.jetskirider.android A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 425 (GLThread 29501)
Try updating your code to match the following:
private void gameOver(Label score) {
for (Body body : worldBodies) {
world.destroyBody(body);
}
dispose();
myGame.setScreen(new GameOver());
}
The first problem was that you were disposing/loading the GameOver
screen inside of your loop instead of after it.
The second problem was with your call to Gdx.app.getApplicationListener()
. Every time you call that it returns a new instance of your Game
. Instead you need to hold on to a reference to your game and instead use that.
If you still get the same error, make sure you are calling dispose()
appropriately. If resources are disposed of before they have been released then you can get some pretty nasty crashes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.