最近、テーブル/ステージ/ボタンなどでlibgdxを使用してMenuScreenを書き始めましたが、次の画面に移動した後でも、元のMenuScreenのボタンはまだクリック可能であることに気付きました:(
これはおおよそ次のようになります。
- アプリが起動し、
MainMenu
画面が表示されます - ボタンをクリックします (例: 「オプション」)。オプション画面を参照してください。
- [オプション] 画面で、MainMenu のボタンがあった場所 (例: About) をクリックします。
- About画面に移動
[オプション] 画面が表示されたときに、MainMenu にボタンがある場所をクリックしないと、[オプション] 画面は通常どおり/期待どおりに機能します。
したがって、この動作から、MainMenu 画面がまだ存在し (非表示になっているだけ)、すべてのボタン リスナーがまだアクティブであるように見えます。
MainMenu 画面をクリーンアップする適切な方法は何ですか? (そして、一般的にlibgdx画面をクリーンアップすると思います)
コードの重要な部分:
public class MainMenu implements Screen {
public MainMenu() {
// ..setting up font, camera etc
stage = new Stage();
stage.setCamera(camera);
Table table = new Table();
table.setWidth(300);
table.setHeight(480);
stage.addActor(table);
TextButton options = new TextButton("Options", buttonStyle);
options.addListener(new ButtonClickListener(app.options));
table.add(options).pad(20);
table.row();
// ... more buttons, eg About...
Gdx.input.setInputProcessor(stage);
}
private class ButtonClickListener extends ClickListener {
private final Screen screen;
private ButtonClickListener(Screen screen) {
this.screen = screen;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
app.setScreen(this.screen);
}
}
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
spriteBatch.begin();
stage.draw();
spriteBatch.end();
}
// ... show(), resize(), hide(), pause(), resume() are all no-ops
@Override
public void dispose() {
stage.dispose();
spriteBatch.dispose();
font.dispose();
}
}