lunny

Phaser Atlas Sprite Size

Recommended Posts

I have a sprite created from atlas.  Everything works fine expect that the sprite is the size of the original image not the trimmed version.

For Example, my sprite is 300x300 but I want it to the trimmed size of 110x93.  How can I do that?

{
    "filename": "stand1",
    "frame": {"x":1077,"y":708,"w":110,"h":93},
    "rotated": false,
    "trimmed": true,
    "spriteSourceSize": {"x":119,"y":98,"w":110,"h":93},
    "sourceSize": {"w":300,"h":300}
}

Share this post


Link to post
Share on other sites

Hi Rich!  I want the sprite's body width/height to be the trimmed values.  My sprite sheet is trimmed but the sprite's body width/height is still displaying the sourceSize of 300x300 instead of the trimmed size.

Some of the code.

this = Phaser.State

this.game.load.atlas(HeroTypes.WARRIOR + '-sprite', 'resources/imgs/heroes/warrior/warrior.png', 'resources/imgs/heroes/warrior/warrior.json');

this = Phaser.Group

this.sprite = this.create(0, 0, HeroTypes.WARRIOR + '-sprite');

Heres the git repo if you want to take a look.

The atlas is loaded in boot.js and the sprite is created in Warrior.js.  

https://github.com/lunzhang/maplefighter

Share this post


Link to post
Share on other sites

I don't have time to look at the repo, sorry - but if it's just the physics body you want to resize then you can do that easily enough (see the example for it), however if you want the Sprite size to be the trimmed size, then you're going to need to trim it before adding it to the atlas.

Share this post


Link to post
Share on other sites

I want the Sprite size and physics body to be the trimmed size.  I did trim the images in the sprite sheet if that's what you mean. I used TexturePacker to trim the images and save it as png and exported the atlas as Phaser JSON.

Share this post


Link to post
Share on other sites

Right, so like I said, you're going to have to trim the frames before adding them to the atlas. Using Photoshop or similar. Whatever dimension the image is when adding to the atlas is the data that gets exported to the JSON files. If you want those dimensions to be different, the source files need to be different.

Share this post


Link to post
Share on other sites

Texture Packer does trim the frames. But it only does so to optimize space used in the atlas and save memory. The data it exports is based on the fact that the original frame size is the one you actually wanted in your game, because that is the size of the sprite you gave it. Texture Packer can also rotate sprites if it will save memory / space to do so - you wouldn't want them to appear rotated in your game, you'd expect them to be the right way around when they render. That is how the trim feature works too.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.