batiste / sprite.js

An efficient javascript sprite animation framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative lastTicksElapsed after Pause/Resume

dpkp opened this issue · comments

Is it expected behavior for ticker.lastTicksElapsed to turn negative after a pause and resume? start and currentTick are reset, but later, in the next() function, _saved is added back to currentTick. This causes lastTicksElapsed to run negative because currentTick [big number] is subtracted from ticksElapsed [small number] in each un-paused run() loop.

current code:

_Ticker.prototype.resume = function() {
// useful to keep the accurate number of ticks after resume
this._saved += ((this.now - this.start) / this.tickDuration) | 0
this.start = new Date().getTime();
this.ticksElapsed = 0;
this.currentTick = 0;
this.paused = false;
this.run();
}

_Ticker.prototype.next = function() {
// number of ticks that have happen tile the last pause
var ticksElapsed = ((this.now - this.start) / this.tickDuration) | 0;
this.lastTicksElapsed = ticksElapsed - this.currentTick;
this.currentTick = ticksElapsed + this._saved;
return this.lastTicksElapsed;
};

I'm not sure what the purpose of "this.currentTick = ticksElapsed + this._saved;" is (why is it useful to keep the accurate number of ticks after resume?), but commenting it out fixes this problem.

Hi,

You are right there was an issue there. The idea is that currentTick should remain accurate if you use it as a basis for physic and animation. The changes I made in the following commit should retain this characteristic without the negative value weirdness:

2974471

Is it fixed for you?

Yes - that fixes the problem for me. Thanks!

On Thu, Sep 8, 2011 at 3:12 AM, Batiste Bieler
reply@reply.github.com
wrote:

Hi,

You are right there was an issue there. The idea is that currentTick should remain accurate if you use it as a basis for physic and animation. The changes I made in the following commit should retain this characteristic without the negative value weirdness:

2974471

Is it fixed for you?

Reply to this email directly or view it on GitHub:
#9 (comment)