Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Eze

I'm from Argentina, my English is not very good, sorry.

I am having trouble wanting to pause a timer created. Just do not, the timer keeps running.

My code is:

this.timer = new ig.Timer(0.5);
this.timer.pause();

Anyone have this problem too.

1 decade ago by alexandre

Are you running impact 1.20? Timer's pause method was introduced in that version.

1 decade ago by Eze

Yes, I have Impact 1.20. I checked the Timer class and pause method does nothing but this:

pause: function() {
if( !this.pausedAt ) {
this.pausedAt = ig.Timer.time;
}
}

1 decade ago by alexandre

How did you come to the conclusion that it was still running?

1 decade ago by Eze

Because the timer to pause the delta value changes.

1 decade ago by alexandre

Docs say
Calling .delta() for paused timers will always return the same value.


A simple test confirms this:
init: function(x, y, settings)
{
  this.parent(x, y, settings);
  this.testTimer = new ig.Timer(1);
},

update: function()
{
  if (this.testTimer.delta() > 0)
  {
    console.log('timer delta = ' + this.testTimer.delta().');
    this.testTimer.pause();
  }
  this.parent();
}

If you want to mute this timer, once paused, add a call to reset:
if (this.testTimer.delta() > 0)
{
  console.log('timer delta = ' + this.testTimer.delta().');
  this.testTimer.reset();
  this.testTimer.pause();
}

1 decade ago by solidgoldrobot

I am experiencing this same issue. I definitely have version 1.20, and pausing timers does not work. Anyone find a solution?

Are we just missing the point of .pause()? It seems to me that the purpose would be to stop delta from advancing before it reaches zero. But in your example it looks like you're not pausing it until it's complete. Not sure what the benefit of that would be...

1 decade ago by dominic

Oh wow, I actually found the issue with this: if you call .pause() in the very first frame of your game (e.g. in the Game&039;s #init() method), it will do nothing.

This is because the global ig.Timer.time is still 0 at this point, so .pausedAt will get set to 0 as well - however, if .pausedAt is 0, the timer will assume it's not paused at all.

A quick workaround for this is to set the initial global time value to something != 0 before you start your game. I.e.:

ig.Timer.time = Number.MIN_VALUE;
ig.main( ... );

Sorry for this. It will be fixed in the next bugfix release.
Page 1 of 1
« first « previous next › last »