Jump to content

Game is not defined?


tobymcfly
 Share

Recommended Posts

Hey guys!

I'm making a game based on states.

This is my Game.js (1st stage) fil starts with this. 

var SpaceChicken = SpaceChicken || {};

The problem is, everything is working except 2 functions. I have a function where you can pickUp boxes but the game crashes whenever i pick it up telling me this error: "image.png.e681389e0a967b20a9ef779f63e07a87.png"

The code i've used looks like this:

image.png.fa5c21ad922445432e570522dcbbd675.png

i have tried putting player.addChild(this.game.make.sprite(25, -150, 'box')); but then it says same error, just with this.make is not defined

 

Any solutions or ideas to prevent this?

Thanks:)

Link to comment
Share on other sites

Well, this it what i would have to replace it with?

And then it obviously won't work. It's weird that it says it isnt defined, when i alreadt defined it? But when i take my gaming code out of the state anatomy, it works fine

state image.PNG

Link to comment
Share on other sites

Sorry im really, really noob at phaser. Only been working with it for 1 week.

How exactly do I know if a variable is global?

And if I do add the window.spacechicken, what changes do i have to do in the code, cause it says spacechiken.game undefined.

Link to comment
Share on other sites

console.log(window.SpaceChicken === SpaceChicken);

If that's true then SpaceChicken is already a global variable.

You don't have to do much different in the other code, you can just use 

var game = SpaceChicken.game;

to get a reference to the game in places where it's not available. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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