Search the Community
Showing results for tags 'phaser.timer'.
-
Hi, To simulate a laser blaster heating and cooling I used setInterval for the cooling and setTimeout to delay the cooling if the weapon overheat (firelimit reached). While the weapon is cooling, if it fires again the cooling is aborted (clearInterval, only if the weapon has not overheated). Although it is working correctly while in game, the cooling or the delay is not paused when the game window loose focus, that's because of setTimeout and setInterval. Here is a demo Blaster heating and cooling, some heating and cooling feedbacks are logged in the browser console and a heating meter in the top right camera corner. The colldown function using setInterval. The overheat handler using setTimeout. The cooldown aborter using clearInterval. The github repo. How should I use Phaser.Timer and Phaser.TimerEvent to implement the same behaviour and then get the cooling timer and cooling delay paused when the game window looses focus.
- 2 replies
-
- phaser
- phaser.timer
-
(and 1 more)
Tagged with:
-
I am a little bit confused about how timers work in Phaser: I understand that the Phaser.Time instance accessible from game.time is responsible for all the internal timing of the engine and also for the timed events we want to add in our games. But I don't understand the following (even after reading the source code) First, the name of the main game timer property game.time.events. It's odd because is a Timer object, not a signal. Shouldn't it be called mainTimer or something like that? I understand it might have this name for historical reasons and a change would break working code, but I'm curious If we want to create new timers we have game.time.add and game.time.create. We can destroy these timers form it's own API (Timer.destroy()) But that doesn't seem to delete them from the _timers array used by the Time instance to update them. We do have Time.removeAll(), but shouldn't we have Time.remove(timer)? . Otherwise we would have a potential memory leak, right?. I saw in the source code that the timers are automatically removed from this list in the Time.update() function if they have no more events to be dispatched, but only if their autoDestroy property is set to true. What if you don't set this property to true? I'm sure I don't want to, because I like to reuse my timers. Am I missing something? Thanks in advance Óscar
- 7 replies
-
- phaser.time
- phaser.timer
-
(and 1 more)
Tagged with: