Adel Posted January 29, 2018 Share Posted January 29, 2018 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. Link to comment Share on other sites More sharing options...
samme Posted January 29, 2018 Share Posted January 29, 2018 Something like this: var coolingDelay = game.time.events.add(COOL_DELAY, onCoolingDelayComplete); var cooldownTimer = game.time.create(); var cooldownLoop = cooldownTimer.loop(COOL_INTERVAL, onCooldownLoop); cooldownTimer.start(); // … cooldownTimer.stop(true); // … cooldownTimer.start(); See the docs. I'd recommend phaser-debug-timer. Adel 1 Link to comment Share on other sites More sharing options...
Adel Posted January 29, 2018 Author Share Posted January 29, 2018 Thanks a lot, it is working perfectly. Link to comment Share on other sites More sharing options...
Recommended Posts