mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Added Tween.pause and Tween.resume.
This commit is contained in:
parent
0470a5e532
commit
3fb432e378
5 changed files with 69 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '85dc7c80-4153-11e7-a2b9-47fa36f39632'
|
||||
build: '688ab350-4157-11e7-98ba-cfca60c8a386'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -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')
|
||||
|
|
19
v3/src/tween/components/Pause.js
Normal file
19
v3/src/tween/components/Pause.js
Normal 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;
|
15
v3/src/tween/components/Resume.js
Normal file
15
v3/src/tween/components/Resume.js
Normal 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;
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue