phaser/v3/src/tween/Tween.js

99 lines
3.1 KiB
JavaScript
Raw Normal View History

var Class = require('../utils/Class');
var TWEEN_CONST = require('./const');
var Tween = new Class({
initialize:
2017-05-17 01:46:58 +00:00
function Tween (manager, data)
{
this.manager = manager;
// An array of TweenData objects, each containing a unique property and target being tweened.
this.data = data;
// data array doesn't change, so we can cache the length
this.totalData = data.length;
2017-05-17 01:46:58 +00:00
// Cached target total (not necessarily the same as the data total)
this.totalTargets = 0;
// If true then duration, delay, etc values are all frame totals
this.useFrames = false;
// Loop this tween? Can be -1 for an infinite loop, or an integer.
// When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD)
this.loop = 0;
// Time in ms/frames before the tween loops.
this.loopDelay = 0;
2017-05-17 01:46:58 +00:00
// How many loops are left to run?
this.loopCounter = 0;
2017-05-17 01:46:58 +00:00
// Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes)
this.completeDelay = 0;
// Countdown timer (used by loopDelay and completeDelay)
this.countdown = 0;
2017-05-25 15:02:40 +00:00
// 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;
// Elapsed time in ms/frames of this run through the Tween.
this.elapsed = 0;
// Total elapsed time in ms/frames of the entire Tween, including looping.
this.totalElapsed = 0;
// Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays
this.duration = 0;
// Value between 0 and 1. The amount through the Tween, excluding loops.
this.progress = 0;
// Time in ms/frames for the Tween to complete (including looping)
this.totalDuration = 0;
// Value between 0 and 1. The amount through the entire Tween, including looping.
this.totalProgress = 0;
this.callbacks = {
onComplete: null,
onLoop: null,
onRepeat: null,
onStart: null,
onUpdate: null,
onYoyo: null
};
this.callbackScope;
},
2017-08-09 16:24:03 +00:00
isPlaying: function ()
{
return (this.state === TWEEN_CONST.ACTIVE);
},
calcDuration: require('./components/CalcDuration'),
2017-05-25 15:02:40 +00:00
init: require('./components/Init'),
loadValues: require('./components/LoadValues'),
nextState: require('./components/NextState'),
2017-05-25 15:02:40 +00:00
pause: require('./components/Pause'),
2017-05-18 05:43:03 +00:00
play: require('./components/Play'),
resetTweenData: require('./components/ResetTweenData'),
2017-05-25 15:02:40 +00:00
resume: require('./components/Resume'),
seek: require('./components/Seek'),
2017-05-18 05:43:03 +00:00
setEventCallback: require('./components/SetEventCallback'),
update: require('./components/Update')
2017-05-09 23:43:28 +00:00
});
module.exports = Tween;