Hello Guest

Author Topic: get a sprite's dimensions without use it on scene  (Read 4576 times)

GyLgames

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
get a sprite's dimensions without use it on scene
« 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...

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: get a sprite's dimensions without use it on scene
« Reply #1 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.

GyLgames

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: get a sprite's dimensions without use it on scene
« Reply #2 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: get a sprite's dimensions without use it on scene
« Reply #3 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?
« Last Edit: June 06, 2012, 03:57:40 pm by unikron »