Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Phaser Atlas Sprite Size


lunny
 Share

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

Link to comment
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

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...