Added Tween.pause and Tween.resume.

This commit is contained in:
photonstorm 2017-05-25 16:02:40 +01:00
parent 0470a5e532
commit 3fb432e378
5 changed files with 69 additions and 12 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '85dc7c80-4153-11e7-a2b9-47fa36f39632'
build: '688ab350-4157-11e7-98ba-cfca60c8a386'
};
module.exports = CHECKSUM;

View file

@ -35,6 +35,9 @@ var Tween = function (manager, data)
// The current state of the tween
this.state = TWEEN_CONST.PENDING_ADD;
// The state of the tween when it was paused (used by Resume)
this._pausedState = TWEEN_CONST.PENDING_ADD;
// Does the Tween start off paused? (if so it needs to be started with Tween.play)
this.paused = false;
@ -71,12 +74,14 @@ Tween.prototype.constructor = Tween;
Tween.prototype = {
init: require('./components/Init'),
calcDuration: require('./components/CalcDuration'),
init: require('./components/Init'),
loadValues: require('./components/LoadValues'),
nextState: require('./components/NextState'),
pause: require('./components/Pause'),
play: require('./components/Play'),
resetTweenData: require('./components/ResetTweenData'),
resume: require('./components/Resume'),
seek: require('./components/Seek'),
setEventCallback: require('./components/SetEventCallback'),
update: require('./components/Update')

View file

@ -0,0 +1,19 @@
var TWEEN_CONST = require('../const');
var Pause = function ()
{
if (this.state === TWEEN_CONST.PAUSED)
{
return;
}
this.paused = true;
this._pausedState = this.state;
this.state = TWEEN_CONST.PAUSED;
return this;
};
module.exports = Pause;

View file

@ -0,0 +1,15 @@
var TWEEN_CONST = require('../const');
var Pause = function ()
{
if (this.state === TWEEN_CONST.PAUSED)
{
this.paused = false;
this.state = this._pausedState;
}
return this;
};
module.exports = Pause;

View file

@ -1,28 +1,46 @@
// var TWEEN_CONST = require('../const');
// For now progress = 0 to 1
var Seek = function (progress)
var Seek = function (toPosition)
{
var marker = this.totalDuration * progress;
var data = this.data;
// Now works on multi-property tweens with varying durations, but doesn't yet factor in delays
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
// This won't work with loop > 0 yet
var ms = this.totalDuration * toPosition;
if (marker >= tweenData.duration)
var tweenData = data[i];
var progress;
var elapsed;
if (ms <= tweenData.delay)
{
tweenData.progress = 1;
tweenData.elapsed = tweenData.duration;
progress = 0;
elapsed = 0;
}
else if (ms >= tweenData.totalDuration)
{
progress = 1;
elapsed = tweenData.duration;
}
else if (ms > tweenData.delay && ms <= tweenData.t1)
{
// Keep it zero bound
ms = Math.max(0, ms - tweenData.delay);
// Somewhere in the first playthru range
progress = ms / tweenData.t1;
elapsed = tweenData.duration * progress;
}
else
{
tweenData.progress = marker / tweenData.duration;
tweenData.elapsed = marker;
// Somewhere in repeat land
}
tweenData.progress = progress;
tweenData.elapsed = elapsed;
var v = tweenData.ease(tweenData.progress);
tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v);