2D Toolkit Forum
2D Toolkit => Support => Topic started by: hromoydron on August 18, 2013, 01:04:09 pm
-
I want to change SpriteCollection while game is playing.
I try simply change name currentIcon.GetComponent<tk2dSprite>().Collection.name=warriorName+"SpriteCollection";But nothing has changed.
Than I try this method:
currentIcon.GetComponent<tk2dSprite>().Collection= (tk2dSpriteCollectionData)Resources.Load(warriorName+"SpriteCollection");
When I make resources.load my collection should be in the folder Resources without other folders between collection and Resourse folder, yes? (I made like this)
But, has got an error :NullReferenceException: Object reference not set to an instance of an object
tk2dBaseSprite.set_Collection (.tk2dSpriteCollectionData value) (at Assets/TK2DROOT/tk2d/Code/Sprites/tk2dBaseSprite.cs:51)
-
The second one is almost correct. You need the sprite collection data object (the one inside the Data folder, and just that, nothing else). You should then be able to load it with Resources.Load. Make sure resources.load is actually loading first though, so print out the value. For obvious reasons if its null it isn't going to work.
Also, use SetSprite to switch to a sprite from the new collection, rather than using .Collection to assign it.
Eg. SetSprite( newCollection, "spriteName" );
-
I make like this:
tk2dSpriteCollectionData currentCollectionData=(tk2dSpriteCollectionData)Resources.Load("bombermanSpriteCollection");
Debug.Log(currentCollectionData);
"bombermanSpriteCollection" is a correct name. But currentData=null. Why?
-
Try this:
tk2dSpriteCollectionData currentCollectionData=(tk2dSpriteCollectionData)Resources.Load("bombermanSpriteCollection", typeof(tk2dSpriteCollectionData));
Also its in a resources folder, right? Its not going to work otherwise.
-
Oh, I wrote Resource - not Resources. Sorry!!!
But without your additions (typeof(tk2dSpriteCollectionData)) it does't work. So thank you!