Hello Guest

Author Topic: How to get the texture of a single sprite, and not the whole Atlas.  (Read 3394 times)

zachprinz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
I know it seems counter productive, but here is my situation.

I am creating an inventory and item system using another add-on called BlindGUI.

The Items when picked up are put into an ItemContainer, which is then put into the Inventories Array.

Each ItemContainer is attached to a OnScreenImage, which represents the item inside of the ItemContainer visually. It's basically a picture that I'm using to pass off interaction to the contained items "WhenClicked" method.

The problem is the Items are all sprites until they are put in the inventory, and I was hoping to be able to load the Items Texture directly from its sprite into the OnScreenImage that's representing it on the inventory.

I tried to use "sprite.Collection.textures[itemSpriteId]" to return the texture but soon realized that that returns the entire Atlas. 

So I'm looking for 1 of 2 things: 1) a way to return the texture of ONLY that sprite. or 2) A way to create a new atlas for every sprite.

Thanks

Also, I hope some of that made since.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to get the texture of a single sprite, and not the whole Atlas.
« Reply #1 on: April 13, 2013, 01:33:16 pm »
You can't get the texture of an atlas entry as it doesn't exist at that point. You can write some code to extract the texture from the atlas if you want. Its not too bad, but you need to take account for rotated&flipped textures.

Creating a new atlas for every sprite will be super expensive, you won't get any batching at all.