Hello Guest

Author Topic: How do I create a Sprite in script?  (Read 4737 times)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9673
    • View Profile
How do I create a Sprite in script?
« on: January 26, 2012, 07:07:01 PM »
The sprite classes aren't meant to be instantiated in code. This is still possible, check tk2dSpriteEditor.DoCreateSpriteObject() for how a sprite is created in the interface.

We recommend you set up prefabs for the sprites you need to instantiate in game and instantiate them instead. That way, you can visually set up your sprite, and you'll be guaranteed everything is set up correctly when you instantiate it in game.

If you need to generate large numbers of sprites by name, simply create one prefab for your sprite collection, instantiate it, and use GetSpriteIdByName() and switch the sprite. This way, you can pool one sprite type per Sprite Collection, and instantiate them the way you need it.