2017-05-17 13:39:49 +00:00
|
|
|
// Merge with Backwards and include in update?
|
2017-05-17 14:40:36 +00:00
|
|
|
var Forward = function (parent, tween, delta)
|
2017-05-17 13:39:49 +00:00
|
|
|
{
|
|
|
|
var elapsed = tween.elapsed;
|
|
|
|
var duration = tween.duration;
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
elapsed += (parent.useFrames) ? 1 : delta;
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
if (elapsed > duration)
|
|
|
|
{
|
|
|
|
elapsed = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
var progress = elapsed / duration;
|
|
|
|
|
|
|
|
var p = tween.ease(progress);
|
|
|
|
|
|
|
|
// Optimize
|
2017-05-17 14:40:36 +00:00
|
|
|
parent.current = parent.start + ((parent.end - parent.start) * p);
|
2017-05-17 13:39:49 +00:00
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
parent.target[parent.key] = parent.current;
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
tween.elapsed = elapsed;
|
|
|
|
tween.progress = progress;
|
|
|
|
|
|
|
|
if (progress === 1)
|
|
|
|
{
|
|
|
|
// Tween has reached end
|
|
|
|
// Do we yoyo or repeat?
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
tween.state = ProcessRepeat(parent, tween);
|
2017-05-17 13:39:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
var Backward = function (parent, tween, delta)
|
2017-05-17 13:39:49 +00:00
|
|
|
{
|
|
|
|
var elapsed = tween.elapsed;
|
|
|
|
var duration = tween.duration;
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
elapsed += (parent.useFrames) ? 1 : delta;
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
if (elapsed > duration)
|
|
|
|
{
|
|
|
|
elapsed = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
var progress = elapsed / duration;
|
|
|
|
|
|
|
|
var p = tween.ease(1 - progress);
|
|
|
|
|
|
|
|
// Optimize
|
2017-05-17 14:40:36 +00:00
|
|
|
parent.current = parent.start + ((parent.end - parent.start) * p);
|
2017-05-17 13:39:49 +00:00
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
parent.target[parent.key] = parent.current;
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
tween.elapsed = elapsed;
|
|
|
|
tween.progress = progress;
|
|
|
|
|
|
|
|
if (progress === 1)
|
|
|
|
{
|
|
|
|
// Tween has reached start
|
|
|
|
// Do we yoyo or repeat?
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
tween.state = ProcessRepeat(parent, tween);
|
2017-05-17 13:39:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
var ProcessRepeat = function (parent, tween)
|
2017-05-17 13:39:49 +00:00
|
|
|
{
|
|
|
|
// Playing forward, and Yoyo is enabled?
|
|
|
|
if (tween.state === 3 && tween.yoyo)
|
|
|
|
{
|
|
|
|
// Play backwards
|
|
|
|
tween.elapsed = 0;
|
|
|
|
tween.progress = 0;
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else if (tween.repeatCounter > 0)
|
|
|
|
{
|
|
|
|
tween.repeatCounter--;
|
|
|
|
|
|
|
|
// Reset the elapsed
|
2017-05-17 14:40:36 +00:00
|
|
|
parent.current = parent.start;
|
|
|
|
|
2017-05-17 13:39:49 +00:00
|
|
|
tween.elapsed = 0;
|
|
|
|
tween.progress = 0;
|
|
|
|
|
|
|
|
// Delay?
|
|
|
|
if (tween.repeatDelay > 0)
|
|
|
|
{
|
|
|
|
tween.countdown = tween.repeatDelay;
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 5;
|
|
|
|
};
|
|
|
|
|
2017-05-17 14:40:36 +00:00
|
|
|
var UpdateTweenData = function (parent, tween, timestep, delta)
|
2017-05-17 13:39:49 +00:00
|
|
|
{
|
|
|
|
if (tween.state === 2)
|
|
|
|
{
|
|
|
|
// Waiting for delay to expire
|
2017-05-17 14:40:36 +00:00
|
|
|
tween.countdown -= (parent.useFrames) ? 1 : delta;
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
if (tween.countdown <= 0)
|
|
|
|
{
|
|
|
|
tween.state = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tween.state === 3)
|
|
|
|
{
|
|
|
|
// Playing forwards
|
2017-05-17 14:40:36 +00:00
|
|
|
Forward(parent, tween, delta);
|
2017-05-17 13:39:49 +00:00
|
|
|
}
|
|
|
|
else if (tween.state === 4)
|
|
|
|
{
|
|
|
|
// Playing backwards
|
2017-05-17 14:40:36 +00:00
|
|
|
Backward(parent, tween, delta);
|
2017-05-17 13:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Complete?
|
2017-05-17 14:40:36 +00:00
|
|
|
return (tween.state === 5);
|
2017-05-17 13:39:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = UpdateTweenData;
|