Jump to content

Noob here, getting this.time.create is not a function. No idea why.


ryebread761
 Share

Recommended Posts

Hi guys, I bet this is a really dumb question, but I can't seem to get timers to work. It's in a state based game, and other calls to the game (this) are working perfectly fine. This is the exact error thrown by FireFox.

TypeError: this.time.create is not a function

Chromium throws:

Uncaught TypeError: Object #<Object> has no method 'create' (index):56States.Game.create (index):56d.StateManager.loadComplete phaser.min.js:4d.Game.loadComplete phaser.min.js:5d.SignalBinding.execute phaser.min.js:4d.Signal.dispatch phaser.min.js:4dispatch phaser.min.js:4d.Loader.nextFile phaser.min.js:10d.Loader.fileComplete phaser.min.js:9a.data.onload

Here is my code (if you need to see more let me know) :

States.Game = function (game) {                 ...                 var timer; };
States.Game.prototype = {                 ...                 create: function () {                    ...                     timer = this.time.create(false);                     timer.add(500, spawnEnemy, this.context);                      timer.start();                 },                 ...}

I'm fairly new to JS (I have the most experience with Java, but am not an expert by any means) so there might be some structure issues with the code. Any help would be appreciated.

Link to comment
Share on other sites

Hi,

are you sure that you initialize time?

 

you have to referense to the game

 

somelike this.

 timer = this.game.time.create(false);

or you have to initialize a time object first

this.time = new Time(game)

hope this helps... 

First one: same issue, second one: Time is not defined???? I should note some thing with this.time work just fine, such as this.time.elapsed has no issues being logged,

Link to comment
Share on other sites

What version of Phaser are you using? The latest stable version is 1.1.6, and this.game.time.create() worked well in it as i tested it. Not sure what's the situation for 1.1.5 or 1.2.

 

Are you trying to do something special with Timer class, or are you just trying to get a timed event working? If you are just trying to create a normal timed event, you don't need to create a new instance of Timer. The example code in my previous post should do the trick as well.

 

 

On unrelated note, I noticed that you created a local variable of timer in your constructor with var timer. That way timer variable is no longer available for you later in your create method. Instead you are creating a global variable timer there, which is probably not what you intended to do.

 

Use this.timer instead:

this.timer = null;...this.timer = this.game.time.create(false);
Link to comment
Share on other sites

 

What version of Phaser are you using? The latest stable version is 1.1.6, and this.game.time.create() worked well in it as i tested it. Not sure what's the situation for 1.1.5 or 1.2.

 

Are you trying to do something special with Timer class, or are you just trying to get a timed event working? If you are just trying to create a normal timed event, you don't need to create a new instance of Timer. The example code in my previous post should do the trick as well.

 

 

On unrelated note, I noticed that you created a local variable of timer in your constructor with var timer. That way timer variable is no longer available for you later in your create method. Instead you are creating a global variable timer there, which is probably not what you intended to do.

 

Use this.timer instead:

this.timer = null;...this.timer = this.game.time.create(false);

Thanks, I thought I was using 1.1.6 but maybe I wasn't. Downloading 1.1.6 from GitHub as zip worked fine, and now this isn't giving issues.

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