Jump to content

Texture Atlas using JSON Hash.


LuckieLordie
 Share

Recommended Posts

When a sprite in my atlas had its trimmed parameter set to true Phaser would fail to load the frame.

 

When I replaced line 45665 in Phaser.js with this.

 

"PIXI.TextureCache[uuid].trim = new Phaser.Rectangle(frames[key].spriteSourceSize.x, frames[key].spriteSourceSize.y, frames[key].sourceSize.w, frames[key].sourceSize.h);"

 

It worked fine. The only change in that code is it's using the "key" variable to address the frame rather than the "i" variable it was being given before. I'm not sure if this will have and knock on effects for anything else so I put it here so you can check it out :P It "shouldn't" do anything adverse since it's inside the function that parses a JSON hash. That's my theory anyway.

 

Hope it helps! 

 

EDIT: here is the whole function so you should be able to find it easier. Also this was on the build that I took at 9am today (17/02/2014)

 

http://pastie.org/private/c7p0wxtdajbmmg0ccsx5ba

Link to comment
Share on other sites

Hmm could you upload (or email me) the atlas + png at all? because I use trimmed sprites all the time without a problem but they always come from Texture Packer, so I'd like to see the format of your json file please.

I can't give you the .png but I can give you the JSON I have?

 

Created using texture packer. http://pastie.org/private/jzuvn1z1e4ixvoeptvww

Link to comment
Share on other sites

  • 5 months later...

Is there a know problem with texture atlas and trimming transparent pixels? After updating to 2.0.7 from 2.0.4 I've noticed my sprites are out of alignment as if the trim data is not loaded correctly. I use TexturePacker with JsonHash. I have to investigate, but maybe there's some change related to this? It used to "just" work.

Link to comment
Share on other sites

I think the change implemented is that the trim data is now correctly used - it used to be the case that the sprites took on the trimmed size rather than the original size, but that shouldn't be how it works. TexturePacker's trimming should be applied in such a fashion that it's only used to pack more sprites into the sprite sheet, and when imported into Phaser, each sprite should take on its original un-trimmed dimensions. If you've previously applied offsets etc to fix the trimming, I'm afraid you're probably going to have to un-apply these!

Link to comment
Share on other sites

Okay, I see the issue a bit. Unfortunately (fortunately) I got no offsets. I specifically had the images the same size and had texturepacker to remove the transparency to fix the images correctly.

 

However I see if you use anchor for sprite, it goes boom and anchor position is offset based on wrong width/height. That causes the sprites to go out of alignment even if you had originally same size frames and used same anchors. I have to revert to older Phaser until this is fixed. Or if this is how it should be.. I'd need to calculate anchor offset based on how much was trimmed. Doesn't sound how it is supposed to work if it's ment to be completely "transparent" for user.

 

EDIT: I probably found the problem and not related to anchor as I first though. The trimming feature has been broken on Phaser.Image based images. I have centralized place to create my objects and I changed it to Phaser.Sprite and the trimming seems to work again. I opted for Phaser.Images as I wanted to save a bit memory space because Sprites have tons of stuff I don't really need. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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