2D Toolkit Forum

2D Toolkit => Support => Topic started by: GyLgames on June 06, 2012, 10:45:44 am

Title: get a sprite's dimensions without use it on scene
Post by: GyLgames on June 06, 2012, 10:45:44 am
hi, there is solution to get dimensions of a sprite (in world unit), without use it on scene? from script...
Title: Re: get a sprite's dimensions without use it on scene
Post by: unikronsoftware on June 06, 2012, 11:00:37 am
You can get it from the tk2dSpriteCollectionData class. Get the appropriate sprite from spriteDefinitions, and use boundsData or untrimmedBoundsData array to get the bounds information.
Check out tk2dBaseSprite.GetBounds() and GetUntrimmedBounds() for how to use the data.
Title: Re: get a sprite's dimensions without use it on scene
Post by: GyLgames on June 06, 2012, 02:38:22 pm
thx, I achieved that.

a minor thing from Reference:

int tk2dSpriteCollectionData.GetSpriteIdByName(string name)
Resolves a sprite name and returns a unique id for the sprite.

Returns:
Unique Sprite Id. 0 if sprite isn't found.


I got 0 for my first sprite, 1 for 2nd sprite.
No diff between the 1st sprite id and not found. Maybe -1 would be better result for not found.
Title: Re: get a sprite's dimensions without use it on scene
Post by: unikronsoftware on June 06, 2012, 02:40:58 pm
That was actually intentional, as it ends up being an array lookup, and having to check array bounds all the time wasn't great - so it fell back to the first thing in the list.
Maybe I should create another version of that function, something like TryGetSpriteIdByName which returns a bool, and writes to an int ref, so at least you'll be aware of it failing.

Edit: Would that work for you?