Gamma Posted March 8, 2014 Share Posted March 8, 2014 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 eventCreate a variable that increases a counter for the next timer that drops another set of itemsonComplete-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 More sharing options...
r00 Posted March 8, 2014 Share Posted March 8, 2014 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. buzzb0x and Robert O'Rourke 1 1 Link to comment Share on other sites More sharing options...
Gamma Posted March 8, 2014 Author Share Posted March 8, 2014 r00, thank you so much man. I'm currently not at my office, so when I get back I'll implement your methods. Thank you so much though. This timer issue is the only thing hindering my game right now. Link to comment Share on other sites More sharing options...
Gamma Posted March 9, 2014 Author Share Posted March 9, 2014 r00 it worked! Thank you so much man! This is awesome! I appreciate your help greatly. Link to comment Share on other sites More sharing options...
Gamma Posted March 9, 2014 Author Share Posted March 9, 2014 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: this.lvl1.stop();It doesn't seem to stop the timer. It identifies it as 'undefined'. I also tried:this.game.time.events.remove(lvl1);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 More sharing options...
Gamma Posted March 9, 2014 Author Share Posted March 9, 2014 Edit: I got it! Just needed to put:this.game.time.removeAll();Thanks for the help guys. Link to comment Share on other sites More sharing options...
Recommended Posts