Hello Guest

Author Topic: Why does GetSpriteIdByName use index 0 for sprite and empty return value  (Read 3076 times)

alex.seeck

  • Newbie
  • *
  • Posts: 18
    • View Profile
The documentation states, that "tk2dSpriteCollectionData.GetSpriteIdByName" "Returns: Unique Sprite Id. 0 if sprite isn't found."

I'm confused why this version exists. There might be an image with the index 0, so you won't be able to tell of it's empty or actually there, both return 0.
I know there's the overloaded version where you can define a default value for checking.
Wouldn't it be better to leave the index of 0 out of the sprite indexes?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Why does GetSpriteIdByName use index 0 for sprite and empty return value
« Reply #1 on: February 03, 2015, 04:19:12 pm »
Its there for backwards compatibility. There might be projects that rely on existing behaviour - the reasoning at the time it was initially written was to always return a valid value where possible, in hindsight not such a good idea.