2D Toolkit Forum

2D Toolkit => Support => Topic started by: glimaleite on January 17, 2014, 12:59:31 pm

Title: Adding a sprite selector to my custom class
Post by: glimaleite on January 17, 2014, 12:59:31 pm
Hello there!

Its my first week using TK2d and I really like it. Now I am a bit stuck on this idea: I'd like to have sprite and collection selectors just like the ones we have when we have the class 2dtkSprite on a game object. I have a generic list of my custom class Slot, and I'd like to have those selectors for each slot that I add to this list.

I couldn't find any info on the forums, so thats why I posted.

Thanks.
Title: Re: Adding a sprite selector to my custom class
Post by: unikronsoftware on January 18, 2014, 11:36:59 pm
The line that draws the sprite selector is in tk2dSpriteEditor.cs
Code: [Select]
tk2dSpriteGuiUtility.SpriteSelector( targetSprites[0].Collection, targetSprites[0].spriteId, spriteChangedCallbackInstance, null );

You need a pair of tk2dSpriteCollectionData and int spriteId to define a sprite.

When a sprite is changed the callback is called you get the new sprite collection + id, and you just assign it to whatever. You get an additional data parameter (null above) which you can use to index into an array, store pointers, etc.