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