Phaser.TweenData = function (parent){ this.parent = parent; this.game = parent.game; this.vStart = { } ; this.vStartCache = { } ; this.vEnd = { } ; this.vEndCache = { } ; this.duration = 1000; this.percent = 0; this.value = 0; this.repeatCounter = 0; this.repeatDelay = 0; this.interpolate = false ; this.yoyo = false ; this.yoyoDelay = 0; this.inReverse = false ; this.delay = 0; this.dt = 0; this.startTime = null ; this.easingFunction = Phaser.Easing.Default; this.interpolationFunction = Phaser.Math.linearInterpolation; this.interpolationContext = Phaser.Math; this.isRunning = false ; this.isFrom = false ; } ; Phaser.TweenData.PENDING = 0; Phaser.TweenData.RUNNING = 1; Phaser.TweenData.LOOPED = 2; Phaser.TweenData.COMPLETE = 3; Phaser.TweenData.prototype = { to: function (properties, duration, ease, delay, repeat, yoyo){ this.vEnd = properties; this.duration = duration; this.easingFunction = ease; this.delay = delay; this.repeatCounter = repeat; this.yoyo = yoyo; this.isFrom = false ; return this; } , from: function (properties, duration, ease, delay, repeat, yoyo){ this.vEnd = properties; this.duration = duration; this.easingFunction = ease; this.delay = delay; this.repeatCounter = repeat; this.yoyo = yoyo; this.isFrom = true ; return this; } , start: function (){ this.startTime = this.game.time.time + this.delay; if (this.parent.reverse) { this.dt = this.duration; } else { this.dt = 0; } if (this.delay > 0) { this.isRunning = false ; } else { this.isRunning = true ; } if (this.isFrom) { for (var property in this.vStartCache){ this.vStart[property] = this.vEndCache[property]; this.vEnd[property] = this.vStartCache[property]; _AN_Read_target('target', this.parent)[property] = this.vStart[property]; } } this.value = 0; this.yoyoCounter = 0; return this; } , loadValues: function (){ for (var property in this.parent.properties){ this.vStart[property] = this.parent.properties[property]; if (Array.isArray(this.vEnd[property])) { if (_AN_Read_length('length', this.vEnd[property]) === 0) { continue ; } if (this.percent === 0) { this.vEnd[property] = [this.vStart[property]] .concat(this.vEnd[property]); } } if (typeof this.vEnd[property] !== 'undefined') { if (typeof this.vEnd[property] === 'string') { this.vEnd[property] = this.vStart[property] + parseFloat(this.vEnd[property], 10); } this.parent.properties[property] = this.vEnd[property]; } else { this.vEnd[property] = this.vStart[property]; } this.vStartCache[property] = this.vStart[property]; this.vEndCache[property] = this.vEnd[property]; } return this; } , update: function (time){ if (!this.isRunning) { if (time >= this.startTime) { this.isRunning = true ; } else { return Phaser.TweenData.PENDING; } } else { if (time < this.startTime) { return Phaser.TweenData.RUNNING; } } if (this.parent.reverse) { this.dt -= this.game.time.elapsedMS * this.parent.timeScale; this.dt = Math.max(this.dt, 0); } else { this.dt += this.game.time.elapsedMS * this.parent.timeScale; this.dt = Math.min(this.dt, this.duration); } this.percent = this.dt / this.duration; this.value = this.easingFunction(this.percent); for (var property in this.vEnd){ var start = this.vStart[property]; var end = this.vEnd[property]; if (Array.isArray(end)) { _AN_Read_target('target', this.parent)[property] = this.interpolationFunction.call(this.interpolationContext, end, this.value); } else { _AN_Read_target('target', this.parent)[property] = start + ((end - start) * this.value); } } if ((!this.parent.reverse && this.percent === 1) || (this.parent.reverse && this.percent === 0)) { return this.repeat(); } return Phaser.TweenData.RUNNING; } , generateData: function (frameRate){ if (this.parent.reverse) { this.dt = this.duration; } else { this.dt = 0; } var data = [] ; var complete = false ; var fps = (1 / frameRate) * 1000; do { if (this.parent.reverse) { this.dt -= fps; this.dt = Math.max(this.dt, 0); } else { this.dt += fps; this.dt = Math.min(this.dt, this.duration); } this.percent = this.dt / this.duration; this.value = this.easingFunction(this.percent); var blob = { } ; for (var property in this.vEnd){ var start = this.vStart[property]; var end = this.vEnd[property]; if (Array.isArray(end)) { blob[property] = this.interpolationFunction(end, this.value); } else { blob[property] = start + ((end - start) * this.value); } } data.push(blob); if ((!this.parent.reverse && this.percent === 1) || (this.parent.reverse && this.percent === 0)) { complete = true ; } } while(!complete)if (this.yoyo) { var reversed = data.slice(); reversed.reverse(); data = data.concat(reversed); } return data; } , repeat: function (){ if (this.yoyo) { if (this.inReverse && this.repeatCounter === 0) { return Phaser.TweenData.COMPLETE; } this.inReverse = !this.inReverse; } else { if (this.repeatCounter === 0) { return Phaser.TweenData.COMPLETE; } } if (this.inReverse) { for (var property in this.vStartCache){ this.vStart[property] = this.vEndCache[property]; this.vEnd[property] = this.vStartCache[property]; } } else { for (var property in this.vStartCache){ this.vStart[property] = this.vStartCache[property]; this.vEnd[property] = this.vEndCache[property]; } if (this.repeatCounter > 0) { this.repeatCounter-- ; } } this.startTime = this.game.time.time; if (this.yoyo && this.inReverse) { this.startTime += this.yoyoDelay; } else if (!this.inReverse) { this.startTime += this.repeatDelay; } if (this.parent.reverse) { this.dt = this.duration; } else { this.dt = 0; } return Phaser.TweenData.LOOPED; } } ; Phaser.TweenData.prototype.constructor = Phaser.TweenData;