Phaser.AnimationParser = { spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing){ var img = game.cache.getImage(key); if (img == null ) { return null ; } var width = img.width; var height = img.height; if (frameWidth <= 0) { frameWidth = Math.floor(- width / Math.min(-1, frameWidth)); } if (frameHeight <= 0) { frameHeight = Math.floor(- height / Math.min(-1, frameHeight)); } var row = Math.floor((width - margin) / (frameWidth + spacing)); var column = Math.floor((height - margin) / (frameHeight + spacing)); var total = row * column; if (frameMax !== -1) { total = frameMax; } if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0) { console.warn("Phaser.AnimationParser.spriteSheet: '" + key + "'s width/height zero or width/height < given frameWidth/frameHeight"); return null ; } var data = new Phaser.FrameData(); var x = margin; var y = margin; for (var i = 0; i < total; i++ ){ var uuid = game.rnd.uuid(); data.addFrame(new Phaser.Frame(i, x, y, frameWidth, frameHeight, '', uuid)); PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[key], { x: x, y: y, width: frameWidth, height: frameHeight} ); x += frameWidth + spacing; if (x + frameWidth > width) { x = margin; y += frameHeight + spacing; } } return data; } , JSONData: function (game, json, cacheKey){ if (!json.frames) { console.warn("Phaser.AnimationParser.JSONData: Invalid Texture Atlas JSON given, missing 'frames' array"); console.log(json); return ; } var data = new Phaser.FrameData(); var frames = json.frames; var newFrame; for (var i = 0; i < _AN_Read_length("length", frames); i++ ){ var uuid = game.rnd.uuid(); newFrame = data.addFrame(new Phaser.Frame(i, frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename, uuid)); PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], { x: frames[i].frame.x, y: frames[i].frame.y, width: frames[i].frame.w, height: frames[i].frame.h} ); if (frames[i].trimmed) { newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h); } } return data; } , JSONDataHash: function (game, json, cacheKey){ if (!json.frames) { console.warn("Phaser.AnimationParser.JSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object"); console.log(json); return ; } var data = new Phaser.FrameData(); var frames = json.frames; var newFrame; var i = 0; for (var key in frames){ var uuid = game.rnd.uuid(); newFrame = data.addFrame(new Phaser.Frame(i, frames[key].frame.x, frames[key].frame.y, frames[key].frame.w, frames[key].frame.h, key, uuid)); PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], { x: frames[key].frame.x, y: frames[key].frame.y, width: frames[key].frame.w, height: frames[key].frame.h} ); if (frames[key].trimmed) { newFrame.setTrim(frames[key].trimmed, frames[key].sourceSize.w, frames[key].sourceSize.h, frames[key].spriteSourceSize.x, frames[key].spriteSourceSize.y, frames[key].spriteSourceSize.w, frames[key].spriteSourceSize.h); } i++ ; } return data; } , XMLData: function (game, xml, cacheKey){ if (!_AN_Call_getelementsbytagname("getElementsByTagName", xml, 'TextureAtlas')) { console.warn("Phaser.AnimationParser.XMLData: Invalid Texture Atlas XML given, missing tag"); return ; } var data = new Phaser.FrameData(); var frames = _AN_Call_getelementsbytagname("getElementsByTagName", xml, 'SubTexture'); var newFrame; var uuid; var name; var frame; var x; var y; var width; var height; var frameX; var frameY; var frameWidth; var frameHeight; for (var i = 0; i < _AN_Read_length('length', frames); i++ ){ uuid = game.rnd.uuid(); frame = frames[i].attributes; name = frame.name.value; x = parseInt(frame.x.value, 10); y = parseInt(frame.y.value, 10); width = parseInt(frame.width.value, 10); height = parseInt(frame.height.value, 10); frameX = null ; frameY = null ; if (frame.frameX) { frameX = Math.abs(parseInt(frame.frameX.value, 10)); frameY = Math.abs(parseInt(frame.frameY.value, 10)); frameWidth = parseInt(frame.frameWidth.value, 10); frameHeight = parseInt(frame.frameHeight.value, 10); } newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid)); PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], { x: x, y: y, width: width, height: height} ); if (frameX !== null || frameY !== null ) { newFrame.setTrim(true , width, height, frameX, frameY, frameWidth, frameHeight); } } return data; } } ;