Jump to content

Timer Issues


Recommended Posts

I implemented a repeated event in which calls a function to drop items on a player. Psuedo code is down below:


Create a variable that stores a timed repeated event

Create a variable that increases a counter for the next timer that drops another set of items

onComplete-incremement the timer so that a trigger notifies another timer to make another repeated event


My problem is the 'onComplete' method. I've been getting a load of errors for a couple hours of trial and error with no avail. Can anyone explain how this works? I want to know the correct syntax for the onComplete method of a timed event.


My trial ended up like this:

lvl1 = this.game.time.events.repeat(Phaser.Timer.SECOND * 4, 10, this.objectDroppingFunction, this);//Level one drops items on the player        lvl1.onComplete(this.incrementCounter, this);//onComplete I call a function that increments the counter//I get the error: Uncaught TypeError: Object [object Object] has no method 'onComplete' 

Thank you all in advance. 



I may have also read the documentation wrong. Does the onComplete check to see if a specific timer has finished or ALL timers? If all timers, than how do I "check" individual timers when they stop individually? 

Link to comment
Share on other sites

As far as I understand, game.time.events.repeat() returns a TimerEvent instance that has no method onComplete.


Instead you probably want to call the onComplete method on the original Timer instance:

this.game.time.events.onComplete.add(this.incrementCounter, this);

Instead, if you need to use timer for something else as well, you should be able to make a new Timer instance, and use it solely for tracking these timer events.


Something like:

this.lvl1Timer = this.game.time.create(false);this.lvl1Timer.start();this.lvl1Timer.onComplete.add(this.incrementCounter, this);this.lvl1Timer.repeat(Phaser.Timer.SECOND * 4, 10, this.objectDroppingFunction, this);

Edit: Corrected the example code. Previous one was written from memory, and turned out to be completely incorrect.

Link to comment
Share on other sites

r00, the timing method worked, but I have one more question. I tried removing the event after the player 'lost' a match, and put this in my update method:


It doesn't seem to stop the timer. It identifies it as 'undefined'. I also tried:


In the update function, and that didn't seem to stop the timer as well. Why is that?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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