问题描述:

When I press the home key and return to my game, a black screen occurs.

I read online that is because textures are lost.

So, I want to know how to keep the texture valid when I resume the game. Are there any reasons for the problem? Any advice will be appreciated.

网友答案:

Generally,There are two reasons for this problem. Firstly,The resource of Texture have been disposed. Secondly,You have load repeated resources.

My problem is the second problem. Because I always create new world in Screen's show method.

My solution,I just need to judge whether the world is null. I only need create the world when it is null.

网友答案:

Based on your reply (as an answer), you can check if the world is null by checking if it's null.

public void resume() {
    If(world == null) { 
        System.out.println("world is null");
        // create world
     } else {
        // do stuff when it's not null.
     }
}

Of course you can reference the world by making it public static when you declare it in play state so you can use it in your core code that extends the ApplicationAdapter.

Edit: Running some tests, I guess you need to set world = null; after calling world.dispose; in the dispose() method.

相关阅读:
Top