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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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