Game Development Reference
In-Depth Information
After this, make the following changes to WorldController :
public WorldController (Game game) {
this.game = game;
init();
}
public void update (float deltaTime) {
handleDebugInput(deltaTime);
if (isGameOver()) {
timeLeftGameOverDelay -= deltaTime;
if (timeLeftGameOverDelay < 0) backToMenu();
} else {
handleInputGame(deltaTime);
}
level.update(deltaTime);
...
}
@Override
public boolean keyUp (int keycode) {
...
// Toggle camera follow
else if (keycode == Keys.ENTER) {
...
}
// Back to Menu
else if (keycode == Keys.ESCAPE || keycode == Keys.BACK) {
backToMenu();
}
return false;
}
The constructor has been extended by taking a reference of the game instance as
an argument, which is then stored for later reference when we need to switch the
screen. In the update() method, a call to backToMenu() is initiated as soon as the
game-over-delay timer runs out of time instead of restarting the game in the game
world as was the case before. As mentioned earlier, we want to handle Android's
back key as well as the Esc key on the desktop ourselves, which is now done inside
the keyUp() method.
You can now run the game and verify that you can switch back and forth between
MenuScreen and GameScreen . Touch the black screen of the menu and try to get back
to it by hitting either the Esc key or the back button, respectively. Losing all lives
while still in the game screen should yield the same result and bring you back to the
menu screen too.
 
Search WWH ::




Custom Search