Book Image

HTML5 Game Development Hotshot

By : Seng Hin Mak, Makzan Makzan (Mak Seng Hin)
Book Image

HTML5 Game Development Hotshot

By: Seng Hin Mak, Makzan Makzan (Mak Seng Hin)

Overview of this book

Table of Contents (15 chapters)
HTML5 Game Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Managing the scenes


In this first task, we will prepare the scenes, which act as a container for all our game objects.

Prepare for lift off

Before creating the scene flow, we prepare the basic scenes definition.

The scene is set up in the same way as the previous project. However, this time we simplified it into two scenes only. Add the following code in the game.js file:

;(function(){
  var game = this.spaceRunner || (this.spaceRunner = {});

  // Main Game Flow
  game.flow = {
    startGame: function() {
      game.gameOverScene.hide();
      game.gameScene.startOver();
    },
    gameOver: function() {
      game.gameOverScene.show();
    }
  };

  // Entry Point
  var init = function() {
    console.log("Welcome to Space Runner Game.");
    game.isGameOver = true;
    game.gameScene.setup();
    game.gameOverScene.setup();
  };
  init();
}).call(this);

Then, we move to the scene.js file to define a scene object. This scene object has basic abilities such as showing and hiding itself. Moreover...