Skip to content

Commit

Permalink
more Tween polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdrowell committed May 12, 2013
1 parent 09c2a46 commit f9277b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
25 changes: 13 additions & 12 deletions src/Tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var blacklist = {
node: 1,
duration: 1,
ease: 1,
easing: 1,
onFinish: 1,
yoyo: 1
},
Expand All @@ -11,19 +11,19 @@
PLAYING = 2,
REVERSING = 3;

function createTween(node, key, ease, end, duration, yoyo) {
function createTween(node, key, easing, end, duration, yoyo) {
var method = 'set' + Kinetic.Util._capitalize(key);
return new Tween(key, function(i) {
node[method](i);
}, ease, node['get' + Kinetic.Util._capitalize(key)](), end, duration * 1000, yoyo);
}, easing, node['get' + Kinetic.Util._capitalize(key)](), end, duration * 1000, yoyo);
}

Kinetic.Tween = function(config) {
var that = this,
node = config.node,
nodeId = node._id,
duration = config.duration || 1,
ease = config.ease || Kinetic.Ease.Linear,
easing = config.easing || Kinetic.Easings.Linear,
yoyo = !!config.yoyo,
key, tween;

Expand All @@ -38,7 +38,7 @@

for (key in config) {
if (blacklist[key] === undefined) {
tween = createTween(node, key, ease, config[key], duration, yoyo);
tween = createTween(node, key, easing, config[key], duration, yoyo);
this.tweens.push(tween);
this._addListeners(tween);
Kinetic.Tween.add(nodeId, key, this);
Expand Down Expand Up @@ -108,11 +108,13 @@
this._iterate(function(tween) {
tween.reset();
});
this.node.getLayer().draw();
},
seek: function(t) {
this._iterate(function(tween) {
tween.seek(t * 1000);
});
this.node.getLayer().draw();
},
pause: function() {
this._iterate(function(tween) {
Expand All @@ -123,6 +125,7 @@
this._iterate(function(tween) {
tween.finish();
});
this.node.getLayer().draw();
},
onEnterFrame: function() {
this._iterate(function(tween) {
Expand All @@ -133,11 +136,9 @@

},
_removeTween: function(prop) {
console.log('remove ' + prop)
var that = this;
this._iterate(function(tween, n) {
if (tween.prop === prop) {
console.log('removed')
that.tweens.splice(n, 1);
}
});
Expand Down Expand Up @@ -265,7 +266,7 @@
* These eases were ported from an Adobe Flash tweening library to JavaScript
* by Xaric
*/
Kinetic.Eases = {
Kinetic.Easings = {
'BackEaseIn': function(t, b, c, d, a, p) {
var s = 1.70158;
return c * (t /= d) * t * ((s + 1) * t - s) + b;
Expand Down Expand Up @@ -362,14 +363,14 @@
}
},
'BounceEaseIn': function(t, b, c, d) {
return c - Kinetic.Ease['bounce-ease-out'](d - t, 0, c, d) + b;
return c - Kinetic.Easings.BounceEaseOut(d - t, 0, c, d) + b;
},
'BounceEaseInOut': function(t, b, c, d) {
if(t < d / 2) {
return Kinetic.Ease['bounce-ease-in'](t * 2, 0, c, d) * 0.5 + b;
return Kinetic.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b;
}
else {
return Kinetic.Ease['bounce-ease-out'](t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
return Kinetic.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
}
},
'EaseIn': function(t, b, c, d) {
Expand All @@ -390,7 +391,7 @@
'StrongEaseOut': function(t, b, c, d) {
return c * (( t = t / d - 1) * t * t * t * t + 1) + b;
},
'StrongEaseIn': function(t, b, c, d) {
'StrongEaseInOut': function(t, b, c, d) {
if((t /= d / 2) < 1) {
return c / 2 * t * t * t * t * t + b;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/js/manualTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ Test.Modules.TRANSITION = {
scaleX: 1.5,
scaleY: 1.5,
duration: 1,
ease: Kinetic.Eases.EaseIn
easing: Kinetic.Easings.EaseIn
});

blueBox.tween = new Kinetic.Tween({
node: blueBox,
scaleX: 1.5,
scaleY: 1.5,
duration: 1,
ease: Kinetic.Eases.EaseOut
easing: Kinetic.Easings.EaseOut
});

redBox.tween = new Kinetic.Tween({
node: redBox,
scaleX: 1.5,
scaleY: 1.5,
duration: 1,
ease: Kinetic.Eases.EaseInOut
easing: Kinetic.Easings.EaseInOut
});

layer.on("mouseover", function(evt) {
Expand Down Expand Up @@ -204,7 +204,7 @@ Test.Modules.TRANSITION = {
x: 400,
scaleX: 2,
scaleY: 2,
ease: Kinetic.Eases.BounceEaseOut,
easing: Kinetic.Easings.BounceEaseOut,
yoyo: false,
onFinish: function() {
console.log('finished!')
Expand All @@ -218,7 +218,7 @@ Test.Modules.TRANSITION = {
node: greenBox,
duration: 2,
x: 200,
ease: Kinetic.Eases.BounceEaseOut,
easing: Kinetic.Easings.BounceEaseOut,
});
tween2.play();
Expand Down

0 comments on commit f9277b8

Please sign in to comment.