Sign in to follow this  
arun

Code not understood

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 = {

Share this post


Link to post
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');

 

Share this post


Link to post
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()).

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.