Game Development Reference
In-Depth Information
Figure 23-2. A screenshot of the overlay shown to the player after they finish a level
You want to display the overlay on top of the playing state, but you don't want the playing state to
be able to process input anymore (otherwise the player could still move penguins around). Therefore,
you only call the update and draw methods, and not the handleInput method, on the playingState
object.
In the handleInput method of LevelFinishedState , you check whether the player has pressed the
mouse button or tapped the screen. If so, you set the current state to be the playing state, and you
call the nextLevel method on it:
LevelFinishedState.prototype.handleInput = function (delta) {
if (powerupjs.Touch.isTouchDevice) {
if (!powerupjs.Touch.containsTouchPress(this.overlay.boundingBox))
return;
}
else if (!powerupjs.Mouse.left.pressed)
return;
powerupjs.GameStateManager.switchTo(ID.game_state_playing);
this.playingState.nextLevel();
};
Search WWH ::




Custom Search