2017-05-17 23:24:25 +00:00
|
|
|
var TWEEN_CONST = require('./const');
|
2017-05-17 13:39:49 +00:00
|
|
|
|
2017-05-24 02:29:31 +00:00
|
|
|
var Tween = function (manager, data)
|
2017-05-09 19:24:39 +00:00
|
|
|
{
|
|
|
|
this.manager = manager;
|
2017-05-09 19:36:29 +00:00
|
|
|
|
2017-05-24 02:29:31 +00:00
|
|
|
// An array of TweenData objects, each containing a unique property and target being tweened.
|
|
|
|
this.data = data;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-24 00:27:04 +00:00
|
|
|
// data array doesn't change, so we can cache the length
|
2017-05-24 02:29:31 +00:00
|
|
|
this.totalData = data.length;
|
|
|
|
|
|
|
|
// Cached target total (not necessarily the same as the data total)
|
|
|
|
this.totalTargets = 0;
|
2017-05-24 00:27:04 +00:00
|
|
|
|
|
|
|
// If true then duration, delay, etc values are all frame totals
|
2017-05-17 13:39:49 +00:00
|
|
|
this.useFrames = false;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-18 02:33:18 +00:00
|
|
|
// Time in ms/frames before the tween starts for the very first time
|
2017-05-24 04:02:14 +00:00
|
|
|
// never used again once the tween has begun, even if it loops.
|
2017-05-18 02:33:18 +00:00
|
|
|
this.startDelay = 0;
|
|
|
|
|
2017-05-19 01:41:26 +00:00
|
|
|
// Infinitely loop this tween?
|
|
|
|
// When enabled it will play through ALL TweenDatas again (doesn't apply to just a single TD)
|
2017-05-17 16:28:01 +00:00
|
|
|
this.loop = false;
|
|
|
|
|
2017-05-17 23:24:25 +00:00
|
|
|
// Time in ms/frames before the tween loops again if loop is true
|
|
|
|
this.loopDelay = 0;
|
|
|
|
|
2017-05-24 02:29:31 +00:00
|
|
|
// Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes)
|
2017-05-17 23:24:25 +00:00
|
|
|
this.completeDelay = 0;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-19 01:41:26 +00:00
|
|
|
// Countdown timer (used by startDelay, loopDelay and completeDelay)
|
2017-05-17 23:24:25 +00:00
|
|
|
this.countdown = 0;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-17 23:24:25 +00:00
|
|
|
this.state = TWEEN_CONST.PENDING_ADD;
|
2017-05-09 19:36:29 +00:00
|
|
|
|
2017-05-17 03:38:00 +00:00
|
|
|
this.paused = false;
|
2017-05-09 19:36:29 +00:00
|
|
|
|
2017-05-17 03:38:00 +00:00
|
|
|
this.callbacks = {
|
|
|
|
onStart: { callback: null, scope: null, params: null },
|
|
|
|
onUpdate: { callback: null, scope: null, params: null },
|
|
|
|
onRepeat: { callback: null, scope: null, params: null },
|
2017-05-24 02:29:31 +00:00
|
|
|
onLoop: { callback: null, scope: null, params: null },
|
2017-05-17 03:38:00 +00:00
|
|
|
onComplete: { callback: null, scope: null, params: null }
|
|
|
|
};
|
2017-05-09 19:36:29 +00:00
|
|
|
|
|
|
|
this.callbackScope;
|
2017-05-09 19:24:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tween.prototype.constructor = Tween;
|
|
|
|
|
|
|
|
Tween.prototype = {
|
2017-05-09 19:36:29 +00:00
|
|
|
|
2017-05-18 05:43:03 +00:00
|
|
|
init: require('./components/Init'),
|
2017-05-17 13:39:49 +00:00
|
|
|
loadValues: require('./components/LoadValues'),
|
2017-05-23 18:04:15 +00:00
|
|
|
nextState: require('./components/NextState'),
|
2017-05-18 05:43:03 +00:00
|
|
|
play: require('./components/Play'),
|
|
|
|
resetTweenData: require('./components/ResetTweenData'),
|
|
|
|
setEventCallback: require('./components/SetEventCallback'),
|
|
|
|
update: require('./components/Update')
|
2017-05-09 23:43:28 +00:00
|
|
|
|
2017-05-09 19:24:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Tween;
|