How to make it so that when you change the settings, the scenes change and work without problems?
In the wallpaper in the settings you can select 2 scenes, with a tank and a bus. The class AndroidLauncher spelled
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); initialize(new AutoRender(), config); } and class AutoRender:
class AutoRender implements ApplicationListener { float screenOffset; boolean settings_changed_flag = false; private Tank tank = new Tank(); private Bus bus = new bus(); int character; @Override public void create() { if (character == 1) tank.create(); if (character == 2) bus.create(); } @Override public void resize(int width, int height) { } @Override public void render() { if (character == 1) tank.render(); if (character == 2) bus.render(); } @Override public void pause() { } @Override public void resume() { } @Override public void dispose() { } } with this code, when switching scenes, an error pops up
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.badlogic.gdx.scenes.scene2d.Stage.act(float)' on a null object reference in the wallpaper itself in the preview goes the inscription that the application is stopped, but then the scene loads and everything works as it should. If you change the create () method of the AutoRender class:
@Override public void create() { tank.create(); bus.create(); } then the scenes switch instantly without error, but the scene with the tank no longer responds to pressing.
And if you leave it as it was, and add
@Override public void resume() { this.resume(); } then the wallpaper reboots when you call or block ..
How to make it so that when you change the settings, the scenes change and work without problems?