2D Toolkit Forum
2D Toolkit => Support => Topic started by: grinay on June 04, 2013, 02:20:59 pm
-
I create Game object
GameObject levelButton = new GameObject("LevelButton",new Type[]{typeof(tk2dSprite),typeof(tk2dButton)});
and i want set the exist sprite collection. Collection in folder Assets/Sprites/GameElements.prefab
How can i do it?
-
You should read up about resources folders in Unity before proceeding.
1. Put the sprite collection data object (i.e. Assets/Sprites/GameElements/GameELements Data/GameElements.prefab) into a resources folder.
2. Load it in using tk2dSpriteCollectionData data = Resources.Load("GameElements", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
3. Get the sprite from levelButton -
tk2dSprite sprite = levelButton.GetComponent<tk2dSprite>();
sprite.SetSprite( data, "nameofsprite" );
-
Thank. It work.
Only i use SwitchCollectionAndSprite
level.GetComponent<tk2dSprite>().SwitchCollectionAndSprite(data,0);
-
Thats fine, though SwitchCollectionAndSprite has been renamed to SetSprite in tk2d 2.0. Something to keep in mind if you update.