Jump to content

Cannot read property 'state' of undefined


smdool
 Share

Recommended Posts

I am looking to extend the Phaser tutorial "Making your first Phaser game" (http://phaser.io/tutorials/making-your-first-phaser-game) by introducing states as described in this post "Understanding Phaser states" (http://www.emanueleferonato.com/2014/08/28/phaser-tutorial-understanding-phaser-states/)

 

The Update function in my play.js provides an overlap callback to a custom function called gameOver (line 161). It is at this point on line 179 whereby this.game, and hence 'state', is undefined as 'this' is now referring to the custom function.

 

The tutorial 'understanding Phaser states' references this.game inside custom functions yet doesn't error.

 

Hoping someone could point myself in the right direction in resolving this issue.

 


Link to comment
Share on other sites

First of all, this does nothing:

 

var play = function(game) {   console.log('play');       var platforms;   var player;   var baddies;   var cursors;   var stars;   var score;   var scoreText;   };  

 

Creating local variables or passing the game parameter to that function only creates those variables inside that function scope and are deleted afterwards.

 

That is the same as doing

var play = function() { console.log('play'); }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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