Game.dispose()或ApplicationListener.dispose()在游戏退出时自动调用。
在这些方法中,您可以处理不断需要的东西,比如纹理,音乐,声音或保存这些对象的assetManager。
class MainClass extends Game....
@Override
public void dispose(){ // this method is called when the game quits
texture1.dispose();
music.dispose();
assetManager.dispose();
}
不过,如果你不再需要一个对象,并且是一次性的,当你不需要它没有更多的,一个例子是像素映射,你应该处理它。
class MainClass extends Game....
Texture texture;
@Override
public void create(){
Pixmap pixmap = new Pixmap(width,height, Pixmap.Format.RGBA8888);
pixmap.setColor(0,0,0,0.5f);
pixmap.fill();
texture = new Texture(pixmap);
pixmap.dispose();
}
Screen
,当你不需要一个屏幕,你处理它
class SplashScreen implements Screen....
public void changeScreen(){
dispose(); //dispose the current screen
setScreen(new Screen());
}
@Override
public void dispose(){ //this method doesnt get called automatically
splashTexture.dispose();
}
那么你可以在画面并将其保存在内存和处理它Game.dispose()虽然
所以在每类中的Dispose方法,只有当整个游戏被关闭状态切换时调用,或者是它,例如,如果你有多个游戏状态,叫什么? – vladutelu
不,自动获取调用的唯一方法是游戏结束时调用的Game.dispose()方法,您对**每个**类有何意义?实现'Screen'的类? – centenond