Phaser.Tween = function (target, game, manager){ this.game = game; _AN_Write_target('target', this, false , target); this.manager = manager; this.timeline = [] ; this.reverse = false ; this.timeScale = 1; this.repeatCounter = 0; this.pendingDelete = false ; this.onStart = new Phaser.Signal(); this.onLoop = new Phaser.Signal(); this.onRepeat = new Phaser.Signal(); this.onChildComplete = new Phaser.Signal(); this.onComplete = new Phaser.Signal(); this.isRunning = false ; this.current = 0; this.properties = { } ; this.chainedTween = null ; this.isPaused = false ; this._onUpdateCallback = null ; this._onUpdateCallbackContext = null ; this._pausedTime = 0; this._codePaused = false ; this._hasStarted = false ; } ; Phaser.Tween.prototype = { to: function (properties, duration, ease, autoStart, delay, repeat, yoyo){ if (typeof duration === 'undefined' || duration <= 0) { duration = 1000; } if (typeof ease === 'undefined') { ease = Phaser.Easing.Default; } if (typeof autoStart === 'undefined') { autoStart = false ; } if (typeof delay === 'undefined') { delay = 0; } if (typeof repeat === 'undefined') { repeat = 0; } if (typeof yoyo === 'undefined') { yoyo = false ; } if (typeof ease === 'string' && this.manager.easeMap[ease]) { ease = this.manager.easeMap[ease]; } if (this.isRunning) { console.warn('Phaser.Tween.to cannot be called after Tween.start'); return this; } this.timeline.push(new Phaser.TweenData(this).to(properties, duration, ease, delay, repeat, yoyo)); if (autoStart) { this.start(); } return this; } , from: function (properties, duration, ease, autoStart, delay, repeat, yoyo){ if (typeof duration === 'undefined') { duration = 1000; } if (typeof ease === 'undefined') { ease = Phaser.Easing.Default; } if (typeof autoStart === 'undefined') { autoStart = false ; } if (typeof delay === 'undefined') { delay = 0; } if (typeof repeat === 'undefined') { repeat = 0; } if (typeof yoyo === 'undefined') { yoyo = false ; } if (typeof ease === 'string' && this.manager.easeMap[ease]) { ease = this.manager.easeMap[ease]; } if (this.isRunning) { console.warn('Phaser.Tween.from cannot be called after Tween.start'); return this; } this.timeline.push(new Phaser.TweenData(this).from(properties, duration, ease, delay, repeat, yoyo)); if (autoStart) { this.start(); } return this; } , start: function (index){ if (typeof index === 'undefined') { index = 0; } if (this.game === null || _AN_Read_target('target', this) === null || _AN_Read_length('length', this.timeline) === 0 || this.isRunning) { return this; } for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ for (var property in this.timeline[i].vEnd){ this.properties[property] = _AN_Read_target('target', this)[property] || 0; if (!Array.isArray(this.properties[property])) { this.properties[property] *= 1; } } } for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ this.timeline[i].loadValues(); } this.manager.add(this); this.isRunning = true ; if (index < 0 || index > _AN_Read_length('length', this.timeline) - 1) { index = 0; } this.current = index; this.timeline[this.current].start(); return this; } , stop: function (complete){ if (typeof complete === 'undefined') { complete = false ; } this.isRunning = false ; this._onUpdateCallback = null ; this._onUpdateCallbackContext = null ; if (complete) { this.onComplete.dispatch(_AN_Read_target('target', this), this); if (this.chainedTween) { this.chainedTween.start(); } } this.manager.remove(this); return this; } , updateTweenData: function (property, value, index){ if (_AN_Read_length('length', this.timeline) === 0) { return this; } if (typeof index === 'undefined') { index = 0; } if (index === -1) { for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ this.timeline[i][property] = value; } } else { this.timeline[index][property] = value; } return this; } , delay: function (duration, index){ return this.updateTweenData('delay', duration, index); } , repeat: function (total, repeatDelay, index){ if (typeof repeatDelay === 'undefined') { repeatDelay = 0; } this.updateTweenData('repeatCounter', total, index); return this.updateTweenData('repeatDelay', repeatDelay, index); } , repeatDelay: function (duration, index){ return this.updateTweenData('repeatDelay', duration, index); } , yoyo: function (enable, yoyoDelay, index){ if (typeof yoyoDelay === 'undefined') { yoyoDelay = 0; } this.updateTweenData('yoyo', enable, index); return this.updateTweenData('yoyoDelay', yoyoDelay, index); } , yoyoDelay: function (duration, index){ return this.updateTweenData('yoyoDelay', duration, index); } , easing: function (ease, index){ if (typeof ease === 'string' && this.manager.easeMap[ease]) { ease = this.manager.easeMap[ease]; } return this.updateTweenData('easingFunction', ease, index); } , interpolation: function (interpolation, context, index){ if (typeof context === 'undefined') { context = Phaser.Math; } this.updateTweenData('interpolationFunction', interpolation, index); return this.updateTweenData('interpolationContext', context, index); } , repeatAll: function (total){ if (typeof total === 'undefined') { total = 0; } this.repeatCounter = total; return this; } , chain: function (){ var i = _AN_Read_length('length', arguments); while (i-- ){ if (i > 0) { arguments[i - 1].chainedTween = arguments[i]; } else { this.chainedTween = arguments[i]; } } return this; } , loop: function (value){ if (typeof value === 'undefined') { value = true ; } if (value) { this.repeatAll(-1); } else { this.repeatCounter = 0; } return this; } , onUpdateCallback: function (callback, callbackContext){ this._onUpdateCallback = callback; this._onUpdateCallbackContext = callbackContext; return this; } , pause: function (){ this.isPaused = true ; this._codePaused = true ; this._pausedTime = this.game.time.time; } , _pause: function (){ if (!this._codePaused) { this.isPaused = true ; this._pausedTime = this.game.time.time; } } , resume: function (){ if (this.isPaused) { this.isPaused = false ; this._codePaused = false ; for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ if (!this.timeline[i].isRunning) { this.timeline[i].startTime += (this.game.time.time - this._pausedTime); } } } } , _resume: function (){ if (this._codePaused) { return ; } else { this.resume(); } } , update: function (time){ if (this.pendingDelete) { return false ; } if (this.isPaused) { return true ; } var status = this.timeline[this.current].update(time); if (status === Phaser.TweenData.PENDING) { return true ; } else if (status === Phaser.TweenData.RUNNING) { if (!this._hasStarted) { this.onStart.dispatch(_AN_Read_target('target', this), this); this._hasStarted = true ; } if (this._onUpdateCallback !== null ) { this._onUpdateCallback.call(this._onUpdateCallbackContext, this, this.timeline[this.current].value, this.timeline[this.current]); } return this.isRunning; } else if (status === Phaser.TweenData.LOOPED) { this.onLoop.dispatch(_AN_Read_target('target', this), this); return true ; } else if (status === Phaser.TweenData.COMPLETE) { var complete = false ; if (this.reverse) { this.current-- ; if (this.current < 0) { this.current = _AN_Read_length('length', this.timeline) - 1; complete = true ; } } else { this.current++ ; if (this.current === _AN_Read_length('length', this.timeline)) { this.current = 0; complete = true ; } } if (complete) { if (this.repeatCounter === -1) { this.timeline[this.current].start(); this.onRepeat.dispatch(_AN_Read_target('target', this), this); return true ; } else if (this.repeatCounter > 0) { this.repeatCounter-- ; this.timeline[this.current].start(); this.onRepeat.dispatch(_AN_Read_target('target', this), this); return true ; } else { this.isRunning = false ; this.onComplete.dispatch(_AN_Read_target('target', this), this); if (this.chainedTween) { this.chainedTween.start(); } return false ; } } else { this.onChildComplete.dispatch(_AN_Read_target('target', this), this); this.timeline[this.current].start(); return true ; } } } , generateData: function (frameRate, data){ if (this.game === null || _AN_Read_target('target', this) === null ) { return null ; } if (typeof data === 'undefined') { data = [] ; } for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ for (var property in this.timeline[i].vEnd){ this.properties[property] = _AN_Read_target('target', this)[property] || 0; if (!Array.isArray(this.properties[property])) { this.properties[property] *= 1; } } } for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ this.timeline[i].loadValues(); } for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ data = data.concat(this.timeline[i].generateData(frameRate)); } return data; } } ; Object.defineProperty(Phaser.Tween.prototype, 'totalDuration', { get: function (){ var total = 0; for (var i = 0; i < _AN_Read_length('length', this.timeline); i++ ){ total += this.timeline[i].duration; } return total; } } ); Phaser.Tween.prototype.constructor = Phaser.Tween;