Game Development Reference
In-Depth Information
p.dispose = function () {
document.onkeydown = null;
document.onkeyup = null;
}
If there are more lives to spare, the hero ship is reset. It is then set to be invincible by invoking its makeInvincible
method. This is so the player has a few seconds to dodge oncoming danger after the game is set back into action. The
health meter is reset and the betweenLevels game property is set back to false , which will resume the action.
If the player is out of lives, the game should end. First, the current score is retrieved and stored in the global game
namespace. Remember, you referenced this value when adding the score to the game over screen. Next, the dispose
method is called and the game event GAME_OVER is dispatched.
The dispose method is created for cleanup before the game scene is removed in the state machine. In this case,
the listeners are removed from the keyboard since they are no longer needed in the application. This also prevents
unwanted results with the keyboard the next time a game instance is created.
That concludes the game code for Space Hero. A lot of code was introduced, which was broken into smaller
sections to help you understand the structure of a high action game. You can find the complete game code in the
Game.js file along with the other source code. You can download the code from the Source Code/Downloads tab on
this topic's Apress product page ( www.apress.com/9781430263401 ). You should be able to follow it from beginning
to end, but if you find yourself stuck on any section of the code, stop and refer back to the section in this chapter that
examined it.
Summary
The game created in this chapter demonstrates how you can organize your loaded assets and game code into several
manageable classes. The concept of object pooling was introduced to enhance the performance in your games, and
the use of the delta property in Ticker can further assure fluid movements when dropping frames. Precise, pixel-
perfect collision detection was also accomplished by taking advantage of an open source, third party library that was
built specifically to work with EaselJS.
In the next chapter, you'll take a look at how a game created with CreateJS can be optimized for mobile browsers.
You'll enhance touch responsiveness and look at ways to scale your games to fit different screen sizes.
 
Search WWH ::




Custom Search