class A4Animation { static fromXML(xml:Element, game:A4Game) : A4Animation { // 74,-1 let a:A4Animation = new A4Animation(); let file:string = xml.getAttribute("file"); a.gf = game.getGraphicFile(file); if (a.gf == null) console.log("A4Animation: cannot get graphic file " + file); a.widthInTiles = Number(xml.getAttribute("dx")); a.heightInTiles = Number(xml.getAttribute("dy")); a.period = Number(xml.getAttribute("period")); if (xml.getAttribute("looping") == "true") a.looping = true; if (xml.getAttribute("seeThrough") == "false") a.seeThrough = false; let sequenceText:string = xml.firstChild.nodeValue; let sequenceFrames:string[] = sequenceText.split(","); a.length = sequenceFrames.length; a.sequence = []; for(let frame of sequenceFrames) { a.sequence.push(Number(frame)); } return a; } static fromAnimation(a:A4Animation) { let a2:A4Animation = new A4Animation(); a2.gf = a.gf; a2.widthInTiles = a.widthInTiles; a2.heightInTiles = a.heightInTiles; a2.period = a.period; a2.looping = a.looping; a2.length = a.length; a2.sequence = []; for(let i:number = 0;i"; for(let i:number = 0;i=this.period) { this.cycle-=this.period; this.state++; if (this.state>=this.length) { if (this.looping) { this.state = 0; } else { this.state = this.length-1; this.completed = true; } } } return this.completed; } draw(x:number, y:number) { let t:number = this.getTile(); if (t<0) return; for(let i:number = 0;i=0) return this.sequence[this.state]; return -1; } getPixelWidth():number { return this.widthInTiles * this.gf.tileWidth; } getPixelHeight():number { return this.heightInTiles * this.gf.tileHeight; } gf:A4GraphicFile = null; widthInTiles:number = 1; heightInTiles:number = 1; period:number = 1; looping:boolean = false; length:number = 0; sequence:number[] = null; cycle:number = 0; state:number = 0; completed:boolean = false; seeThrough:boolean = true; }