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...