diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 83f73faa6..f261d5377 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '85dc7c80-4153-11e7-a2b9-47fa36f39632' +build: '688ab350-4157-11e7-98ba-cfca60c8a386' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/tween/Tween.js b/v3/src/tween/Tween.js index a2dd40a41..f1618b0c5 100644 --- a/v3/src/tween/Tween.js +++ b/v3/src/tween/Tween.js @@ -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') diff --git a/v3/src/tween/components/Pause.js b/v3/src/tween/components/Pause.js new file mode 100644 index 000000000..3e902972d --- /dev/null +++ b/v3/src/tween/components/Pause.js @@ -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; diff --git a/v3/src/tween/components/Resume.js b/v3/src/tween/components/Resume.js new file mode 100644 index 000000000..f106c9c91 --- /dev/null +++ b/v3/src/tween/components/Resume.js @@ -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; diff --git a/v3/src/tween/components/Seek.js b/v3/src/tween/components/Seek.js index a7e86a305..2e5c1564d 100644 --- a/v3/src/tween/components/Seek.js +++ b/v3/src/tween/components/Seek.js @@ -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);