Sign in to follow this  
J4G

Load spritesheet from texture atlas

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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;        }

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.