diff --git a/v3/src/tween/GetEaseFunction.js b/v3/src/tween/GetEaseFunction.js new file mode 100644 index 000000000..7ae8fa6bd --- /dev/null +++ b/v3/src/tween/GetEaseFunction.js @@ -0,0 +1,23 @@ +var EaseMap = require('../math/easing/EaseMap'); + +var GetEaseFunction = function (ease) +{ + if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease)) + { + // String based look-up + return EaseMap[ease]; + } + else if (typeof ease === 'function') + { + // Custom function + return ease; + } + else if (Array.isArray(ease) && ease.length === 4) + { + // Bezier function (TODO) + } + + return EaseMap.Power0; +}; + +module.exports = GetEaseFunction; diff --git a/v3/src/tween/Tween.js b/v3/src/tween/Tween.js index 2b6965793..651b39024 100644 --- a/v3/src/tween/Tween.js +++ b/v3/src/tween/Tween.js @@ -1,4 +1,6 @@ var GetValue = require('../utils/object/GetValue'); +var GetEaseFunction = require('./GetEaseFunction'); +var CloneObject = require('../utils/object/Clone'); var TweenData = require('./TweenData'); var RESERVED = [ 'targets', 'ease', 'duration', 'yoyo', 'repeat', 'loop', 'paused', 'useFrames', 'offset' ]; @@ -69,7 +71,13 @@ var Tween = function (manager, config) this.targets = this.setTargets(GetValue(config, 'targets', null)); - this.ease; + // The properties on the targets that are being tweened. + // The properties are tween simultaneously. + // This object contains the properties which each has an array of TweenData objects, + // that are updated in sequence. + this.props = {}; + + this.ease = GetEaseFunction(GetValue(config, 'ease', 'Power0')); this.duration = GetValue(config, 'duration', 1000); @@ -78,9 +86,29 @@ var Tween = function (manager, config) this.yoyo = GetValue(config, 'yoyo', false); this.repeat = GetValue(config, 'repeat', 0); + this.delay = GetValue(config, 'delay', 0); + this.onCompleteDelay = GetValue(config, 'onCompleteDelay', 0); - // same as repeat -1 (if set, overrides repeat value) - this.loop = GetValue(config, 'loop', undefined); + // Short-cut for repeat -1 (if set, overrides repeat value) + this.loop = GetValue(config, 'loop', false); + + if (this.repeat === -1) + { + this.loop = true; + } + + this.defaultTweenData = { + value: undefined, + progress: 0, + startTime: 0, + ease: this.ease, + duration: this.duration, + yoyo: this.yoyo, + repeat: this.repeat, + loop: this.loop, + delay: this.delay, + startAt: undefined + }; this.paused = GetValue(config, 'paused', false); @@ -104,6 +132,8 @@ var Tween = function (manager, config) this.callbackScope; + this.buildTweenData(config); + }; Tween.prototype.constructor = Tween; @@ -112,6 +142,48 @@ Tween.prototype = { // Move to own functions + getV: function (obj, key) + { + if (obj.hasOwnProperty(key)) + { + return obj[key]; + } + else if (this[key]) + { + return this[key]; + } + }, + + buildTweenData: function (config) + { + // For now let's just assume `config.props` is being used: + + // this.defaultTweenData = { + // value: undefined, + // progress: 0, + // startTime: 0, + // ease: this.ease, + // duration: this.duration, + // yoyo: this.yoyo, + // repeat: this.repeat, + // loop: this.loop, + // delay: this.delay, + // startAt: undefined + // }; + + for (var key in config.props) + { + var data = CloneObject(this.defaultTweenData); + + this.props[key] = + } + }, + + update: function (timestep, delta) + { + + }, + setTargets: function (targets) { if (typeof targets === 'function') diff --git a/v3/src/tween/TweenData.js b/v3/src/tween/TweenData.js index d6799843d..cb6870ebf 100644 --- a/v3/src/tween/TweenData.js +++ b/v3/src/tween/TweenData.js @@ -1,9 +1,10 @@ +/* var TweenData = function (parent) { this.tween = parent; this.property; - + this.value; this.ease; @@ -23,6 +24,26 @@ TweenData.prototype = { +}; +*/ + +// Could this just be a data bag? + +var TweenData = function (config) +{ + this.property = ; + + this.value; + + this.ease; + this.duration; + this.yoyo; + this.repeat; + this.delay; + this.startAt; + this.onCompleteDelay; + this.elasticity; + }; module.exports = TweenData;