Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

pause the game using Phaser's timer class


Yehuda Katz
 Share

Recommended Posts

Hello,

I know Phaser has built in timer. I assume it's designed to support game pause. Could anyone share idea, how game pause should be implemented? Lets assume I used only Phaser's timer class. Is there any way to stop them all and later resume them all? Of course I can do it manually for each timer, but what if later I will add some more or I miss some? It's better to have some kind of global pause for all timers =)

Thanks in advance

Link to comment
Share on other sites

Thanks @samme but as far as I know, the correct syntax for marking property/method as private is prefixing it with "_".

What is the best way to stop game.time.totalElapsedSeconds() without calling gamePaused()? I need that to stop counting time while game prepares new challenge for user.

p.s. I also found your another answer regarding game.time.events.add VERY helpful as I needed to have native setTimeout equivalent method =)

Link to comment
Share on other sites

@samme I had to go back to original timer because game.time.events has no option to reset counter.

this.game_timer = this.game.time.create(false);
this.game_timer.loop(60000, function() {});
this.game_timer.start();
this.game_timer.pause();

I had to add that dummy loop event to be able to calculate time passed (this.game_timer.seconds). I thinks this is not right way to do it :(

BTW have you any idea why the same code will not work if I replace first line with

this.game_timer = new Phaser.Timer(this.game, false);

Thanks in advance for your time

Link to comment
Share on other sites

@samme thanks, I tried without empty loop and it still works fine. I do not use native game.time.events because it stops all other timers (game.time.events.add). However, if I create timer like that it does not count anything:

this.game_timer = new Phaser.Timer(this.game, false);

As for reset @samid737 - it does not work on my end... after first call stop(), start() the timer start counting in reverse and giving negative values for seconds property (also seconds never get reset).

With custom timer I simply destroy old and create new one to reset it OR I have to add my own loop and count time by my own

Link to comment
Share on other sites

7 hours ago, Yehuda Katz said:

this.game_timer = new Phaser.Timer(this.game, false);

It won't work this way because the timer never gets updated. You need to use

this.game_timer = this.time.create(false);

 

Edited by samme
Use `time.create` not `time.add`
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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