Jump to content

Timer bug when game paused or timer missuse


crouzilles
 Share

Recommended Posts

Hi,

 

I have created a timer like this:

   //  Create our Timer    timer = game.time.create(false);    //  Set a event to occur after 20 seconds    timer.loop(20000, do_stuff, this);

I have setup the spacebar to pause or unpause the game like this:

    // add keyboard controls    var pauseKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);    pauseKey.onDown.add(toggle_pause)

When the player hits the spacebar, the game gets paused or unpaused like this:

    function toggle_pause() {        game.paused = !game.paused;        if (!game.paused) {            timer.resume();        } else {           timer.pause();        }    }

When ever I pause the game let's say for 30 seconds, then unpause the game, the timer will not be called for another 50 seconds (20 seconds for timer + 30 seconds of pause time).

 

I have tested this with shorter and longer pause times, I get the same effect (20 seconds of timer + N seconds of pause time).

 

Am I using the timer wrongly or is this a bug?

Regards

Crouz

Link to comment
Share on other sites

Shouldn't it be like this?

  function toggle_pause() {        game.paused = !game.paused;        if (!game.paused) {            timer.pause();        } else {           timer.resume();        }    }

Also, have you tried pausing the game without manually pausing the timer?

Link to comment
Share on other sites

Shouldn't it be like this?

  function toggle_pause() {        game.paused = !game.paused;        if (!game.paused) {            timer.pause();        } else {           timer.resume();        }    }

Also, have you tried pausing the game without manually pausing the timer?

Pausing the game without pausing the timer did the trick, thanks darkraziel

 

Crouz

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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