Yehuda Katz

pause the game using Phaser's timer class

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

Share this post


Link to post
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 =)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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`

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.