mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
tween array fixes
This commit is contained in:
parent
77f9af4e06
commit
8006bed344
13
src/Tween.js
13
src/Tween.js
@ -216,7 +216,7 @@
|
||||
_addAttr: function(key, end) {
|
||||
var node = this.node,
|
||||
nodeId = node._id,
|
||||
start, diff, tweenId, n, len, trueEnd;
|
||||
start, diff, tweenId, n, len, trueEnd, trueStart;
|
||||
|
||||
// remove conflict from tween map if it exists
|
||||
tweenId = Konva.Tween.tweens[nodeId][key];
|
||||
@ -238,6 +238,7 @@
|
||||
|
||||
if (end.length > start.length) {
|
||||
// so in this case we will increase number of starting points
|
||||
trueStart = start;
|
||||
start = Konva.Util._prepareArrayForTween(start, end, node.closed());
|
||||
} else {
|
||||
// in this case we will increase number of eding points
|
||||
@ -267,7 +268,8 @@
|
||||
start: start,
|
||||
diff: diff,
|
||||
end: end,
|
||||
trueEnd: trueEnd
|
||||
trueEnd: trueEnd,
|
||||
trueStart: trueStart
|
||||
};
|
||||
Konva.Tween.tweens[nodeId][key] = this._id;
|
||||
},
|
||||
@ -330,6 +332,13 @@
|
||||
}
|
||||
};
|
||||
this.tween.onReset = function() {
|
||||
var node = that.node;
|
||||
// after tweening points of line we need to set original start
|
||||
var attrs = Konva.Tween.attrs[node._id][that._id];
|
||||
if (attrs.points && attrs.points.trueStart) {
|
||||
node.points(attrs.points.trueStart);
|
||||
}
|
||||
|
||||
if (that.onReset) {
|
||||
that.onReset();
|
||||
}
|
||||
|
@ -277,6 +277,63 @@ suite('Tween', function() {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('tween array to lower size and go back', function(done) {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var line = new Konva.Line({
|
||||
stroke: 'black',
|
||||
points: [100, 100, 200, 100, 200, 200, 100, 200],
|
||||
closed: true
|
||||
});
|
||||
layer.add(line);
|
||||
|
||||
var tween = new Konva.Tween({
|
||||
node: line,
|
||||
points: [100, 100, 200, 100, 200, 200],
|
||||
duration: 0.01,
|
||||
onFinish: function() {
|
||||
tween.reverse();
|
||||
},
|
||||
onReset: function() {
|
||||
assert.deepEqual(line.points(), [100, 100, 200, 100, 200, 200, 100, 200]);
|
||||
done();
|
||||
}
|
||||
});
|
||||
tween.play();
|
||||
});
|
||||
|
||||
test('tween array to bigger size and go back', function(done) {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var line = new Konva.Line({
|
||||
stroke: 'black',
|
||||
points: [100, 100, 200, 100, 200, 200],
|
||||
closed: true
|
||||
});
|
||||
layer.add(line);
|
||||
|
||||
var tween = new Konva.Tween({
|
||||
node: line,
|
||||
points: [100, 100, 200, 100, 200, 200, 100, 200],
|
||||
duration: 0.01,
|
||||
onFinish: function() {
|
||||
tween.reverse();
|
||||
},
|
||||
onReset: function() {
|
||||
assert.deepEqual(line.points(), [100, 100, 200, 100, 200, 200]);
|
||||
done();
|
||||
}
|
||||
});
|
||||
tween.play();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user