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

Restart / Stop a timer?


iShellz
 Share

Recommended Posts

timer=game.time.events.loop(Phaser.Timer.SECOND, gameFunction(), this);. 

 

 

this.timer.destroy();

reset all values and create the timer again?

 

I do this :)

Thanks for this , i switched formats to this type when i couldn't figure it out but i'll probably go back to save a few lines haha.

Loop = game.time.create(true);Loop.add(Phaser.Timer.SECOND, function(), this);Loop.start();
Link to comment
Share on other sites

  • 2 years later...

I just implemented it the following way:

First, I store the timer itself and the loop in two different variables
 

timer = game.time.events;
loop = timer.loop(timeOut, fall, this);

Later in the game, when I need to change the pace of the loop, I use the loop object:
 

loop.delay -= speedUp;

But if I want to pause/resume, the I need to interact with the timer object:
 

function managePauseScreen(){
        pauseState = !pauseState;
        if(pauseState){
            timer.pause();
        }else{
            timer.resume();
        }
    }

These two object thus give me all the flexibility I need, and the solution is elegant!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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