function Animation() { this.dx = 1; this.dy = 1; this.period = 1; this.file = null; this.looping = false; this.tileEntry = undefined; this.sequence = [0]; // reset the animation: this.cycle = 0; this.state = 0; this.completed = false; this.clone = function() { var a = new Animation(); a.dx = this.dx; a.dy = this.dy; a.period = this.period; a.file = this.file; a.looping = this.looping; a.tileEntry = this.tileEntry; a.sequence = this.sequence; a.cycle = this.cycle; a.state = this.state; a.completed = this.completed; return a; } this.reset = function() { this.cycle = 0; this.state = 0; } this.update = function() { this.cycle++; if (this.cycle>=this.period) { this.cycle-=this.period; this.state++; if (this.state>=this.sequence.length) { if (this.looping) { this.state = 0; } else { this.state = this.sequence.length-1; this.completed = true; } } } } this.isCompleted = function() { return this.completed; } this.getWidth = function() { return this.dx; } this.getHeight = function() { return this.dy; } this.getTile = function() { return this.sequence[this.state]; } this.getTileEntry = function(game) { if (this.tileEntry==undefined) { if (game==null) return; this.tileEntry = game.tiles[this.file] } return this.tileEntry; } this.draw = function(x,y,alpha,game) { if (this.tileEntry==undefined) { if (game==null) return; this.tileEntry = game.tiles[this.file]; } if (this.sequence[this.state]!=-1) { for(var i = 0;i