2D Toolkit Forum

2D Toolkit => Support => Topic started by: alex.seeck on February 03, 2015, 03:49:24 pm

Title: Why does GetSpriteIdByName use index 0 for sprite and empty return value
Post by: alex.seeck on February 03, 2015, 03:49:24 pm
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?
Title: Re: Why does GetSpriteIdByName use index 0 for sprite and empty return value
Post by: unikronsoftware 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.