2017-05-17 23:24:25 +00:00
|
|
|
var TWEEN_CONST = require('./const');
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
// A Tween is responsible for tweening one property of one target.
|
|
|
|
// If a target has many properties being tweened, then each unique property will be its own Tween object.
|
|
|
|
// This allows us to have differing ease, duration and associated events per property.
|
|
|
|
// A Tween contains TweenData objects (at least one). It can contain more than one TweenData,
|
|
|
|
// in which case they play out like a nested timeline, all impacting just the one target property.
|
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
var Tween = function (manager, targets, tweenData)
|
2017-05-09 19:24:39 +00:00
|
|
|
{
|
|
|
|
this.manager = manager;
|
2017-05-09 19:36:29 +00:00
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
// Array of targets being tweened (TweenTarget objects)
|
|
|
|
this.targets = targets;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
// targets array size doesn't change, so we can cache the length
|
|
|
|
this.totalTargets = targets.length;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
this.data = tweenData;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
// An object with a property matching those being tweened by this Tween.
|
|
|
|
// The list arrays contain TweenData instances in a linked-list format.
|
|
|
|
//
|
|
|
|
// {
|
|
|
|
// x: {
|
|
|
|
// current: TweenData reference
|
|
|
|
// list: []
|
|
|
|
// },
|
|
|
|
// y: {
|
|
|
|
// current: TweenData reference
|
|
|
|
// list: []
|
|
|
|
// }
|
|
|
|
// }
|
2017-05-17 13:39:49 +00:00
|
|
|
|
|
|
|
// if true then duration, delay, etc values are all frame totals
|
|
|
|
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
|
|
|
|
// (populated by stagger property, or directly) - never used again once the
|
|
|
|
// tween has begun.
|
|
|
|
this.startDelay = 0;
|
|
|
|
|
2017-05-17 23:24:25 +00:00
|
|
|
// infinitely loop this tween? Maybe a string? 'alternate', 'reverse', etc
|
|
|
|
// When enabled it will play through
|
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-17 13:39:49 +00:00
|
|
|
// Time in ms/frames before the 'onComplete' event fires
|
2017-05-17 23:24:25 +00:00
|
|
|
this.completeDelay = 0;
|
2017-05-17 01:46:58 +00:00
|
|
|
|
2017-05-18 05:39:47 +00:00
|
|
|
// delta countdown timer (used by startDelay and loopDelay)
|
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 },
|
|
|
|
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-17 13:39:49 +00:00
|
|
|
init: require('./components/Init'),
|
2017-05-18 05:39:47 +00:00
|
|
|
play: require('./components/Play'),
|
|
|
|
resetTweenData: require('./components/ResetTweenData'),
|
|
|
|
update: require('./components/Update'),
|
|
|
|
calcTargetsValue: require('./components/CalcTargetsValue'),
|
|
|
|
resetTargetsValue: require('./components/ResetTargetsValue'),
|
|
|
|
setEventCallback: require('./components/SetEventCallback'),
|
2017-05-17 13:39:49 +00:00
|
|
|
loadValues: require('./components/LoadValues'),
|
2017-05-18 05:39:47 +00:00
|
|
|
nextTweenData: require('./components/NextTweenData'),
|
2017-05-17 14:40:36 +00:00
|
|
|
setCurrentTweenData: require('./components/SetCurrentTweenData'),
|
2017-05-09 23:43:28 +00:00
|
|
|
|
2017-05-09 19:24:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Tween;
|