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

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

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...