mirror of
https://github.com/konvajs/konva.git
synced 2026-01-18 19:51:21 +08:00
improved batch draw logic. Each layer isntance now has access to its own batch draw animation
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
(function() {
|
||||
var BATCH_DRAW_STOP_TIME_DIFF = 500;
|
||||
|
||||
/**
|
||||
* Animation constructor. A stage is used to contain multiple layers and handle
|
||||
* @constructor
|
||||
@@ -235,24 +237,27 @@
|
||||
moveTo.call(this, container);
|
||||
};
|
||||
|
||||
Kinetic.Layer.batchAnim = new Kinetic.Animation(function() {
|
||||
if (this.getLayers().length === 0) {
|
||||
this.stop();
|
||||
}
|
||||
this.setLayers([]);
|
||||
});
|
||||
|
||||
/**
|
||||
* get batch draw
|
||||
* @method
|
||||
* @memberof Kinetic.Layer.prototype
|
||||
*/
|
||||
Kinetic.Layer.prototype.batchDraw = function() {
|
||||
var batchAnim = Kinetic.Layer.batchAnim;
|
||||
batchAnim.addLayer(this);
|
||||
var that = this;
|
||||
|
||||
if (!batchAnim.isRunning()) {
|
||||
batchAnim.start();
|
||||
}
|
||||
if (!this.batchAnim) {
|
||||
this.batchAnim = new Kinetic.Animation(function() {
|
||||
if (that.lastBatchDrawTime && new Date().getTime() - that.lastBatchDrawTime > BATCH_DRAW_STOP_TIME_DIFF) {
|
||||
that.batchAnim.stop();
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
this.lastBatchDrawTime = new Date().getTime();
|
||||
|
||||
if (!this.batchAnim.isRunning()) {
|
||||
this.draw();
|
||||
this.batchAnim.start();
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -54,7 +54,7 @@ Test.Modules.ANIMATION = {
|
||||
anim.stop();
|
||||
test(a.animations.length === 0, '7should be no animations running');
|
||||
},
|
||||
'batch draw': function(containerId) {
|
||||
'*batch draw': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
@@ -91,8 +91,10 @@ Test.Modules.ANIMATION = {
|
||||
layer.batchDraw();
|
||||
layer.batchDraw();
|
||||
|
||||
test(Kinetic.Layer.batchAnim.getLayers().length === 1, 'batch animation should only have one layer');
|
||||
|
||||
test(draws !== 6, 'should not be 6 draws');
|
||||
|
||||
setTimeout(function() {
|
||||
layer.batchDraw();
|
||||
}, 2000);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user