/// /** * Phaser - Animation * * An Animation is a single animation. It is created by the AnimationManager and belongs to Sprite objects. */ var Phaser; (function (Phaser) { var Animation = (function () { function Animation(game, parent, frameData, name, frames, delay, looped) { this._game = game; this._parent = parent; this._frames = frames; this._frameData = frameData; this.name = name; this.delay = 1000 / delay; this.looped = looped; this.isFinished = false; this.isPlaying = false; this._frameIndex = 0; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); } Object.defineProperty(Animation.prototype, "frameTotal", { get: function () { return this._frames.length; }, enumerable: true, configurable: true }); Object.defineProperty(Animation.prototype, "frame", { get: function () { return this._frameIndex; }, set: function (value) { this.currentFrame = this._frameData.getFrame(value); if(this.currentFrame !== null) { this._parent.bounds.width = this.currentFrame.width; this._parent.bounds.height = this.currentFrame.height; this._frameIndex = value; } }, enumerable: true, configurable: true }); Animation.prototype.play = function (frameRate, loop) { if (typeof frameRate === "undefined") { frameRate = null; } if(frameRate !== null) { this.delay = 1000 / frameRate; } if(loop !== undefined) { this.looped = loop; } this.isPlaying = true; this.isFinished = false; this._timeLastFrame = this._game.time.now; this._timeNextFrame = this._game.time.now + this.delay; this._frameIndex = 0; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); }; Animation.prototype.restart = function () { this.isPlaying = true; this.isFinished = false; this._timeLastFrame = this._game.time.now; this._timeNextFrame = this._game.time.now + this.delay; this._frameIndex = 0; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); }; Animation.prototype.stop = function () { this.isPlaying = false; this.isFinished = true; }; Animation.prototype.update = function () { if(this.isPlaying == true && this._game.time.now >= this._timeNextFrame) { this._frameIndex++; if(this._frameIndex == this._frames.length) { if(this.looped) { this._frameIndex = 0; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); } else { this.onComplete(); } } else { this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); } this._timeLastFrame = this._game.time.now; this._timeNextFrame = this._game.time.now + this.delay; return true; } return false; }; Animation.prototype.destroy = function () { this._game = null; this._parent = null; this._frames = null; this._frameData = null; this.currentFrame = null; this.isPlaying = false; }; Animation.prototype.onComplete = function () { this.isPlaying = false; this.isFinished = true; // callback }; return Animation; })(); Phaser.Animation = Animation; })(Phaser || (Phaser = {}));