Jump to content

Code not understood


arun
 Share

Recommended Posts

Hi friends,

I am new in Phaser game development. When I followed a tutorial monster wants candy  i found the following  codes that I don't understand. Please help me.

var Candy = {};
Candy.Boot = function(game){};
Candy.Boot.prototype = {

Link to comment
Share on other sites

This is a namespacing technique.

It creates a single global variable, Candy, and saves all the State classes there.

It will make a little more sense if you look ahead at

game.state.add('Boot', Candy.Boot);
game.state.add('Preloader', Candy.Preloader);
game.state.add('MainMenu', Candy.MainMenu);
game.state.add('Game', Candy.Game);
game.state.start('Boot');

 

Link to comment
Share on other sites

Quote

'Boot' is a state name and Candy.Boot is an object (defined in the next steps) that will be executed when we start that state. We're adding states for Boot (configuration), Preloader (loading assets), MainMenu(you guessed it; the main menu of our game) and Game (the main loop of the game). The last line, game.state.start('Boot'), starts the Boot state, so that the proper function from the Candy.Boot object will be executed.

As you can see, there's one main JavaScript game object created, with many others assigned within for special purposes. In our game we have Boot, Preloader, MainMenu, and Game objects which will be our game states, and we define them by using their prototypes. There are a few special function names inside those objects reserved for the framework itself (preload(), create(), update(), and render()), but we can also define our own (startGame(), spawnCandy(), managePause()).

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...