J4G Posted May 15, 2015 Share Posted May 15, 2015 I'm using a texture atlas generated by TexturePacker. Within this atlas I have images that are spritesheets, containing multiple frames from an animation. How can I load these animations from a single image properly without using game.load.spritesheet? Link to comment Share on other sites More sharing options...
Tom Atom Posted May 15, 2015 Share Posted May 15, 2015 Hi, while having spritesheet nested in atlas is strange and I can not imagine use for it, I see two possibilities: 1) not for animation, but for displaying: use crop rectangle on sprite that has that spritesheet as frame to display only the part you need (actually, you can do animation by updating the cropRect, but it means to do the animation handling by yourself), or 2) after loading this atlas add additional processing for spritesheets within it. In this processing add additional Frames to framedata of atlas. This code adds frame to framedata for "aKey" atlas. Call it with aKey = atlas, aFrame = you new frame name, aX,aY - top left corner in atlas, aWidth, aHeight - dimensions. Then, you can use these frames in animation or anywhere else. private addFrame(aKey:string, aFrame: string, aX: number, aY: number, aWidth: number, aHeight: number) : Phaser.Frame { var frameData: Phaser.FrameData = this.game.cache.getFrameData(aKey); var uuid = this.game.rnd.uuid(); var newFrame = frameData.addFrame(new Phaser.Frame(frameData.total, aX, aY, aWidth, aHeight, aFrame, uuid.toString())); PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[aKey], <PIXI.Rectangle> { x: aX, y: aY, width: aWidth, height: aHeight }); return newFrame; } J4G 1 Link to comment Share on other sites More sharing options...
stupot Posted May 15, 2015 Share Posted May 15, 2015 Commonly, I will use separate spritesheets during development as they can be easily updated. Also they may be supplied from another source (eg gfx supplier) so it is easiest to work with them direct. I use atlas's to group together separate resources into a single file for release version. This development/release usage is important. Phaser doesn't natively handle spritesheets embedded in an Atlas, it would be nice if it did. As Tom suggests, there are ways around this. Anotherway would be to deconstruct your spritesheet into separate files and add these into the atlas. But eitherway, whichever approach you use, there will be extra pre-processing or runtime code. J4G 1 Link to comment Share on other sites More sharing options...
J4G Posted May 15, 2015 Author Share Posted May 15, 2015 Thanks for the responses, both of you. I guess I'll probably just change the way I manage my spritesheets. Link to comment Share on other sites More sharing options...
stupot Posted May 18, 2015 Share Posted May 18, 2015 Of course, the other option is to modify the Phaser code to allow this to happen, then offer it back to the community. Link to comment Share on other sites More sharing options...
Recommended Posts