Jump to content

states question


IvesN
 Share

Recommended Posts

Hi, i just recently started using phaser, (and programming in general :P). im reading about phaser states and looking at examples i see this repeated in some of them

 

var game = new Phaser.Game(width, height, Phaser.AUTO, 'test');

 
var BasicGame = function(game) {};
 
BasicGame.Boot = function (game) {};
 
BasicGame.Boot.prototype = etc etc .
 
could someone explain me what are the advantages of using this pattern and not just use game.state.add. I have some understanding of prototype ineritance but can't figure this 
Link to comment
Share on other sites

It's for readability, extensibility (you could share functions between states and extend/modify them) and it keeps your code cleanly separated. Also, if you tried to add the state directly like so:

game.state.add("SomeState", {   create: function() {    // blah blah  },  update: function() {    // blah blah blay  }}

You'll find scope rather tricky to work with from within the state; 'this' will not work as expected. You're best off keeping things more verbose otherwise maintainability of your code will quickly deteriorate.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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