mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Simplify onFrame handling.
This commit is contained in:
parent
c1dc823706
commit
3bd4db802c
1 changed files with 6 additions and 7 deletions
|
@ -169,8 +169,8 @@ var DocumentView = this.DocumentView = Base.extend({
|
|||
this._onFrame = onFrame;
|
||||
var that = this,
|
||||
running = false,
|
||||
lastTime,
|
||||
totalTime = 0,
|
||||
before,
|
||||
time = 0,
|
||||
count = 0;
|
||||
function frame(dontSwitch) {
|
||||
if (!that._onFrame) {
|
||||
|
@ -182,17 +182,16 @@ var DocumentView = this.DocumentView = Base.extend({
|
|||
// Request next frame already
|
||||
DomEvent.requestAnimationFrame(frame, that._canvas);
|
||||
running = true;
|
||||
var time = Date.now() / 1000,
|
||||
delta = lastTime ? time - lastTime : 0;
|
||||
totalTime += delta;
|
||||
var now = Date.now() / 1000,
|
||||
delta = before ? now - before : 0;
|
||||
that._onFrame({
|
||||
delta: delta, // Time elapsed since last redraw in seconds
|
||||
time: totalTime, // Time since first call of frame() in seconds
|
||||
time: time += delta, // Time since first call of frame() in seconds
|
||||
count: count++
|
||||
});
|
||||
before = now;
|
||||
// Automatically draw view on each frame.
|
||||
that.draw();
|
||||
lastTime = time;
|
||||
};
|
||||
// Call the onFrame handler straight away, initializing the sequence
|
||||
// of onFrame calls.
|
||||
|
|
Loading…
Reference in a new issue