mirror of
https://github.com/konvajs/konva.git
synced 2025-12-04 19:08:24 +08:00
fixed animation race condition bug that sometimes produced multiple requestAnimFrame calls, and also changed throttle property to be in fps (it used to be in ms). This will make it more consistent with other properties related to frame rates
This commit is contained in:
@@ -16,6 +16,7 @@ Kinetic.GlobalObject = {
|
||||
tempNodes: [],
|
||||
animations: [],
|
||||
animIdCounter: 0,
|
||||
animRunning: false,
|
||||
dragTimeInterval: 0,
|
||||
maxDragTimeInterval: 20,
|
||||
frame: {
|
||||
@@ -104,12 +105,14 @@ Kinetic.GlobalObject = {
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.animRunning = false;
|
||||
this.frame.lastTime = 0;
|
||||
}
|
||||
},
|
||||
_handleAnimation: function() {
|
||||
var that = this;
|
||||
if(this.animations.length > 0) {
|
||||
if(!this.animRunning) {
|
||||
this.animRunning = true;
|
||||
that._animationLoop();
|
||||
}
|
||||
else {
|
||||
|
||||
22
src/Layer.js
22
src/Layer.js
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
Kinetic.Layer = function(config) {
|
||||
this.setDefaultAttrs({
|
||||
throttle: 12
|
||||
throttle: 80
|
||||
});
|
||||
|
||||
this.nodeType = 'Layer';
|
||||
@@ -40,10 +40,11 @@ Kinetic.Layer.prototype = {
|
||||
var date = new Date();
|
||||
var time = date.getTime();
|
||||
var timeDiff = time - this.lastDrawTime;
|
||||
var tt = 1000 / throttle;
|
||||
|
||||
if(timeDiff >= throttle) {
|
||||
if(timeDiff >= tt) {
|
||||
this._draw();
|
||||
this.lastDrawTime = time;
|
||||
|
||||
if(this.drawTimeout !== undefined) {
|
||||
clearTimeout(this.drawTimeout);
|
||||
this.drawTimeout = undefined;
|
||||
@@ -55,15 +56,12 @@ Kinetic.Layer.prototype = {
|
||||
*/
|
||||
else if(this.drawTimeout === undefined) {
|
||||
var that = this;
|
||||
/*
|
||||
* if timeout duration is too short, we will
|
||||
* get a lot of unecessary layer draws. Make sure
|
||||
* that the timeout is slightly more than the throttle
|
||||
* amount
|
||||
*/
|
||||
/*
|
||||
* wait 17ms before trying again (60fps)
|
||||
*/
|
||||
this.drawTimeout = setTimeout(function() {
|
||||
that.draw();
|
||||
}, throttle + 10);
|
||||
}, 17);
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -133,6 +131,10 @@ Kinetic.Layer.prototype = {
|
||||
* private draw children
|
||||
*/
|
||||
_draw: function() {
|
||||
var date = new Date();
|
||||
var time = date.getTime();
|
||||
this.lastDrawTime = time;
|
||||
|
||||
// before draw handler
|
||||
if(this.beforeDrawFunc !== undefined) {
|
||||
this.beforeDrawFunc();
|
||||
|
||||
Reference in New Issue
Block a user