Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - traemyn

Pages: [1]
1
Support / Basic question(s) on creating sprites during runtime
« on: December 11, 2012, 05:10:39 pm »
I am new to Unity and 2D Toolkit so I'll outline what I am doing below in case someone wants to point out any general Unity mistakes while answering my toolkit questions.  ;)

I am working on a card game and I have created multiple SpriteCollections and loaded the card textures into them (~60 cards per collection; maxing out the atlas size of each). Each 'card' has a unique name (unique to all SpriteCollections).

To create the sprite gameobjects during runtime, I envision the following occurring:

I have a 'finder' function that I will pass the name of the card. Inside this function it will loop through all SpriteCollections for that name and then create the sprite (gameobject) with the appropriate info, from the appropriate SpriteCollection.

Questions:
1. Is there a faster/better way to do the 'finder' function part? Am I missing some basic functionality that already exists in the SpriteCollections/2D Toolkit?

2. While trying to implement this finder function, I ran into a problem that my SpriteCollections are not showing up in the intellisense and don't seem to 'exist' so that the code can reference them. I tried GameObject.Find but that is not working. How can I reference those SpriteCollections in the code?

Thanks!

EDIT: I think one of the FAQ posts answers some of this actually.
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,24.0.html

"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."

I still need to know what prefab to create (since I have multiple sprite collections). Should I just create a lookup table that has a <cardname><prefab name exists in> instead of trying to search through all existing SpriteCollections?

Pages: [1]