mirror of
https://github.com/photonstorm/phaser
synced 2024-11-16 17:58:23 +00:00
Working on BaseTween again so Chain can share the features
This commit is contained in:
parent
bdbadd1339
commit
6c2fc3fcba
4 changed files with 1253 additions and 104 deletions
1014
src/tweens/tween/BaseTween.js
Normal file
1014
src/tweens/tween/BaseTween.js
Normal file
File diff suppressed because it is too large
Load diff
|
@ -329,18 +329,6 @@ var Tween = new Class({
|
|||
*/
|
||||
this.persist = false;
|
||||
|
||||
/**
|
||||
* If this Tween has been chained to another tween, this contains a reference to that tween.
|
||||
*
|
||||
* See the `Tween.chain` method for more details.
|
||||
*
|
||||
* @name Phaser.Tweens.Tween#chainedTween
|
||||
* @type {Phaser.Tweens.Tween}
|
||||
* @default null
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.chainedTween = null;
|
||||
|
||||
/**
|
||||
* The delta used in the current update.
|
||||
*
|
||||
|
@ -350,8 +338,6 @@ var Tween = new Class({
|
|||
* @since 3.60.0
|
||||
*/
|
||||
this.delta = 0;
|
||||
|
||||
this.debug = [];
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -363,22 +349,15 @@ var Tween = new Class({
|
|||
* @fires Phaser.Tweens.Events#TWEEN_ACTIVE
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {boolean} [isChained=false] - Is this Tween chained to another?
|
||||
*
|
||||
* @return {this} This Tween instance.
|
||||
*/
|
||||
init: function (isChained)
|
||||
init: function ()
|
||||
{
|
||||
if (isChained === undefined) { isChained = false; }
|
||||
|
||||
this.initTweenData();
|
||||
|
||||
if (!isChained)
|
||||
{
|
||||
this.setActiveState();
|
||||
this.setActiveState();
|
||||
|
||||
this.dispatchEvent(Events.TWEEN_ACTIVE, 'onActive');
|
||||
}
|
||||
this.dispatchEvent(Events.TWEEN_ACTIVE, 'onActive');
|
||||
|
||||
return this;
|
||||
},
|
||||
|
@ -419,39 +398,6 @@ var Tween = new Class({
|
|||
return tweenData;
|
||||
},
|
||||
|
||||
/**
|
||||
* Chain a Tween to be started as soon as this Tween reaches an 'onComplete' state.
|
||||
*
|
||||
* If this Tween never achieves 'onComplete' (i.e. has been set to loop or repeat forever),
|
||||
* then the chained Tween will not be started unless the `Tween.complete` method is called.
|
||||
*
|
||||
* You cannot chain a Tween that is already in a sequence of Tweens.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#chain
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.Tweens.Tween} [tween] - The Tween to chain to this Tween, or don't pass an argument to remove a chain.
|
||||
*
|
||||
* @return {this} This Tween instance.
|
||||
*/
|
||||
chain: function (tween)
|
||||
{
|
||||
var tweens = this.getChainedTweens();
|
||||
|
||||
if (tweens.indexOf(tween) === -1)
|
||||
{
|
||||
this.chainedTween = tween;
|
||||
|
||||
if (tween)
|
||||
{
|
||||
// Needs to be told its a chained tween, or it'll start playing
|
||||
tween.setChainedState();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the value of the time scale applied to this Tween. A value of 1 runs in real-time.
|
||||
* A value of 0.5 runs 50% slower, and so on.
|
||||
|
@ -752,14 +698,6 @@ var Tween = new Class({
|
|||
this.setPendingRemoveState();
|
||||
|
||||
this.dispatchEvent(Events.TWEEN_COMPLETE, 'onComplete');
|
||||
|
||||
// console.log(this.debug);
|
||||
|
||||
// Chain ...
|
||||
if (this.chainedTween)
|
||||
{
|
||||
this.chainedTween.setActiveState();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1259,7 +1197,6 @@ var Tween = new Class({
|
|||
* @since 3.60.0
|
||||
*
|
||||
* @return {Phaser.Tweens.Tween[]} An array of the chained tweens, or an empty array if there aren't any.
|
||||
*/
|
||||
getChainedTweens: function ()
|
||||
{
|
||||
var result = [];
|
||||
|
@ -1289,6 +1226,7 @@ var Tween = new Class({
|
|||
|
||||
return result;
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets this Tween state to PENDING.
|
||||
|
@ -1378,17 +1316,6 @@ var Tween = new Class({
|
|||
this.state = TWEEN_CONST.DESTROYED;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to CHAINED.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setChainedState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setChainedState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.CHAINED;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `true` if this Tween has a _current_ state of PENDING, otherwise `false`.
|
||||
*
|
||||
|
@ -1493,19 +1420,6 @@ var Tween = new Class({
|
|||
return (this.state === TWEEN_CONST.DESTROYED);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `true` if this Tween has a _current_ state of CHAINED, otherwise `false`.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#isChained
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @return {boolean} `true` if this Tween has a _current_ state of CHAINED, otherwise `false`.
|
||||
*/
|
||||
isChained: function ()
|
||||
{
|
||||
return (this.state === TWEEN_CONST.CHAINED);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the destroy process of this Tween, clearing out the
|
||||
* Tween Data and resetting the targets. A Tween that has been
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
var EventEmitter = require('eventemitter3');
|
||||
var Events = require('../events');
|
||||
var TWEEN_CONST = require('./const');
|
||||
var TweenBuilder = require('../builders/TweenBuilder');
|
||||
|
@ -15,6 +16,7 @@ var TweenBuilder = require('../builders/TweenBuilder');
|
|||
*
|
||||
* @class TweenChain
|
||||
* @memberof Phaser.Tweens
|
||||
* @extends Phaser.Events.EventEmitter
|
||||
* @constructor
|
||||
* @since 3.60.0
|
||||
*
|
||||
|
@ -22,10 +24,14 @@ var TweenBuilder = require('../builders/TweenBuilder');
|
|||
*/
|
||||
var TweenChain = new Class({
|
||||
|
||||
Extends: EventEmitter,
|
||||
|
||||
initialize:
|
||||
|
||||
function TweenChain (manager)
|
||||
{
|
||||
EventEmitter.call(this);
|
||||
|
||||
/**
|
||||
* A reference to the TweenManager that this TweenChain instance belongs to.
|
||||
*
|
||||
|
@ -59,6 +65,60 @@ var TweenChain = new Class({
|
|||
*/
|
||||
this.timeScale = 1;
|
||||
|
||||
/**
|
||||
* Loop this tween? Can be -1 for an infinite loop, or a positive integer.
|
||||
*
|
||||
* When enabled it will play through ALL TweenDatas again. Use TweenData.repeat to loop a single element.
|
||||
*
|
||||
* @name Phaser.Tweens.Tween#loop
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.loop = 0;
|
||||
|
||||
/**
|
||||
* Time in ms/frames before the Tween loops.
|
||||
*
|
||||
* @name Phaser.Tweens.Tween#loopDelay
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.loopDelay = 0;
|
||||
|
||||
/**
|
||||
* Internal counter recording how many loops are left to run.
|
||||
*
|
||||
* @name Phaser.Tweens.Tween#loopCounter
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.loopCounter = 0;
|
||||
|
||||
/**
|
||||
* The time in ms/frames before the 'onComplete' event fires.
|
||||
*
|
||||
* This never fires if loop = -1 (as it never completes)
|
||||
*
|
||||
* @name Phaser.Tweens.Tween#completeDelay
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.completeDelay = 0;
|
||||
|
||||
/**
|
||||
* An internal countdown timer (used by loopDelay and completeDelay)
|
||||
*
|
||||
* @name Phaser.Tweens.Tween#countdown
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.countdown = 0;
|
||||
|
||||
/**
|
||||
* The time, in milliseconds, before this tween will start playing.
|
||||
*
|
||||
|
@ -217,10 +277,7 @@ var TweenChain = new Class({
|
|||
|
||||
if (this.currentIndex === this.data.length)
|
||||
{
|
||||
// We're at the end of the chain - for now, let's just pause the chain
|
||||
console.log('chain over');
|
||||
|
||||
this.paused = true;
|
||||
this.nextState();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -235,6 +292,74 @@ var TweenChain = new Class({
|
|||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method that advances to the next state of the Tween during playback.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#nextState
|
||||
* @fires Phaser.Tweens.Events#TWEEN_COMPLETE
|
||||
* @fires Phaser.Tweens.Events#TWEEN_LOOP
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {boolean} `true` if this Tween has completed, otherwise `false`.
|
||||
*/
|
||||
nextState: function ()
|
||||
{
|
||||
if (this.loopCounter > 0)
|
||||
{
|
||||
this.loopCounter--;
|
||||
|
||||
this.resetTweens();
|
||||
|
||||
if (this.loopDelay > 0)
|
||||
{
|
||||
this.countdown = this.loopDelay;
|
||||
|
||||
this.setLoopDelayState();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setActiveState();
|
||||
|
||||
this.dispatchEvent(Events.TWEEN_LOOP, 'onLoop');
|
||||
}
|
||||
}
|
||||
else if (this.completeDelay > 0)
|
||||
{
|
||||
this.countdown = this.completeDelay;
|
||||
|
||||
this.setCompleteDelayState();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onCompleteHandler();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Internal method that resets all of the Tween Data, including the progress and elapsed values.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#resetTweenData
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {boolean} resetFromLoop - Has this method been called as part of a loop?
|
||||
*/
|
||||
resetTweens: function ()
|
||||
{
|
||||
var data = this.data;
|
||||
|
||||
for (var i = 0; i < data.length; i++)
|
||||
{
|
||||
data[i].resetTweenData(true);
|
||||
}
|
||||
|
||||
this.currentIndex = 0;
|
||||
this.currentTween = this.data[0];
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the value of the time scale applied to this Tween. A value of 1 runs in real-time.
|
||||
* A value of 0.5 runs 50% slower, and so on.
|
||||
|
@ -402,6 +527,73 @@ var TweenChain = new Class({
|
|||
this.state = TWEEN_CONST.ACTIVE;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to LOOP_DELAY.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setLoopDelayState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setLoopDelayState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.LOOP_DELAY;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to COMPLETE_DELAY.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setCompleteDelayState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setCompleteDelayState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.COMPLETE_DELAY;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to PENDING_REMOVE.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setPendingRemoveState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setPendingRemoveState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.PENDING_REMOVE;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to REMOVED.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setRemovedState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setRemovedState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.REMOVED;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to FINISHED.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setFinishedState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setFinishedState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.FINISHED;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets this Tween state to DESTROYED.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#setDestroyedState
|
||||
* @since 3.60.0
|
||||
*/
|
||||
setDestroyedState: function ()
|
||||
{
|
||||
this.state = TWEEN_CONST.DESTROYED;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Returns `true` if this Tween has a _current_ state of PENDING, otherwise `false`.
|
||||
*
|
||||
|
@ -428,6 +620,32 @@ var TweenChain = new Class({
|
|||
return (this.state === TWEEN_CONST.ACTIVE);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `true` if this Tween has a _current_ state of LOOP_DELAY, otherwise `false`.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#isLoopDelayed
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @return {boolean} `true` if this Tween has a _current_ state of LOOP_DELAY, otherwise `false`.
|
||||
*/
|
||||
isLoopDelayed: function ()
|
||||
{
|
||||
return (this.state === TWEEN_CONST.LOOP_DELAY);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `true` if this Tween has a _current_ state of COMPLETE_DELAY, otherwise `false`.
|
||||
*
|
||||
* @method Phaser.Tweens.Tween#isCompleteDelayed
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @return {boolean} `true` if this Tween has a _current_ state of COMPLETE_DELAY, otherwise `false`.
|
||||
*/
|
||||
isCompleteDelayed: function ()
|
||||
{
|
||||
return (this.state === TWEEN_CONST.COMPLETE_DELAY);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns `true` if this Tween has a _current_ state of PENDING_REMOVE, otherwise `false`.
|
||||
*
|
||||
|
@ -488,6 +706,18 @@ var TweenChain = new Class({
|
|||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
for (var i = 0; i < this.data.length; i++)
|
||||
{
|
||||
this.data[i].destroy();
|
||||
}
|
||||
|
||||
this.removeAllListeners();
|
||||
|
||||
this.callbacks = null;
|
||||
this.data = null;
|
||||
this.manager = null;
|
||||
|
||||
this.setDestroyedState();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -157,16 +157,7 @@ var TWEEN_CONST = {
|
|||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
DESTROYED: 27,
|
||||
|
||||
/**
|
||||
* Tween state. The is a chained Tween and is awaiting playback.
|
||||
*
|
||||
* @name Phaser.Tweens.CHAINED
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
CHAINED: 28
|
||||
DESTROYED: 27
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue