0

It's possible to create a Sprite from a TextureAtlas region with the original non-trimmed size of the image?

I have an Atlas with images that are trimmed, but I want to get the original image with whitespaces to create a Sprite; AtlasRegion have the original values of width and height.

riu999
  • 46
  • 4

1 Answers1

0

If you are only trying to get the original size of the unstripped image, you can already get that with atlasSprite.getWidth() and atlasSprite.getHeight() as long as you haven't yet called setWidth(), setHeight(), setSize(), or setBounds() on it.

But to create a sprite that actually has and draws that white space is not really possible, because the trimming occurs when the texture is packed. That white space does not exist in the image file or the Texture because there are neighboring regions packed closely together. (Though I suppose you could draw the sprite onto a Pixmap, leaving white space around it, and load that in a Texture, and then create a Sprite from that, but this is convoluted.)

If you want to keep the white space, you must keep it when packing the texture atlas. You can set the stripWhitespaceX and stripWhitespaceY parameters to false when packing.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154