Game Development Reference
In-Depth Information
public void hide () {
worldRenderer.dispose();
Gdx.input.setCatchBackKey(false);
}
@Override
public void pause () {
paused = true;
}
@Override
public void resume () {
super.resume();
// Only called on Android!
paused = false;
}
}
You should recognize most of the preceding code as it is merely a duplicate of
the current
CanyonBunnyMain
class. However, some small changes have been
made. First of all, the code that was in the
create()
and
dispose()
methods of
CanyonBunnyMain
have been moved over to the
show()
and
hide()
methods,
respectively, in order to accommodate the
Screen
interface. Furthermore, catching
Android's back key will be enabled when the game screen is shown and disabled
again when the screen is hidden. This allows us to handle this event and execute a
custom action (here, switch back to the menu screen) in place of the system's default
action, which is to terminate the running application.
Now, let's fix
CanyonBunnyMain
. For clarity and brevity, we will just replace the
whole class as most of its code has to be removed anyway.
Replace the current content of
CanyonBunnyMain
with the following code:
package com.packtpub.libgdx.canyonbunny;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.packtpub.libgdx.canyonbunny.game.Assets;
import com.packtpub.libgdx.canyonbunny.screens.MenuScreen;
public class CanyonBunnyMain extends Game {