Hi,
I want to retrieve the 'native/standard' size of a sprite prior to instantiating one. This would be fairly simple to do except that I'm also using multiple platforms on the sprite collection. Running spriteCollectionData.GetSpriteDefinition() results in an exception because the spriteDefinition array has no elements. (Is that correct, or a bug?) Instead, one has to go spriteCollectionData.inst.GetSpriteDefinition(), which works, but will return a different definition based on which platform is currently active. (I.e. At 2x I'd get say, 40x40, and at 4x I'd get 80x80)
In terms of setting positions and sizes of sprites, I'm working at 1024x768, which corresponds with the '2x' sprite collection. So, when I want to retrieve a sprite's width, I always want the 2x measurement, effectively allowing me to ignore the 4x platform's existence.
I've written the following code which works around this issue, but am concerned about it being unsupported:
tk2dSpriteCollectionData spriteCollectionDataInst = this.spriteGroup.SpriteCollectionData.inst;
tk2dSpriteDefinition definition = spriteCollectionDataInst.GetSpriteDefinition(this.name);
Bounds bounds = definition.GetBounds();
size = new IntVector2(
Mathf.RoundToInt(bounds.size.x * spriteCollectionDataInst.halfTargetHeight),
Mathf.RoundToInt(bounds.size.y * spriteCollectionDataInst.halfTargetHeight)
);
As you can see, I access the .inst and retrieve the definition for the current platform, then multiply the bounds by the current platform's halfTargetHeight to get the 'native' size.
Is there a better way to achieve this, or is the above an acceptable way of doing it?