2D Toolkit Forum

2D Toolkit => Support => Topic started by: negative_zero on August 01, 2014, 06:21:34 am

Title: Confused about the best way to use sprites in my sprite collection
Post by: negative_zero on August 01, 2014, 06:21:34 am
So, I created a sprite collection and imported a spritesheet just fine, it chopped it up nicely.  All of my pieces look perfect.  However, I need to use the pieces as individual sprites that I am connecting a bunch of code to and creating individual prefabs from. 

I know that I can do create -> tk2d -> sprite and then select the piece that I want.  However, I have a good 100+ pieces, and eventually will have a good 1,000+.  Is there a way to just create a whole batch of sprites at once using a sprite collection?  They would all have the same exact properties, so I feel like this should be possible, but I can't seem to find it anywhere.  It seems like it would take a long, long time to create them all one by one.

Or maybe there is something else I'm missing?  I know when you chop up a spritesheet in Unity 4.3 it automatically creates all of the individual sprites...
Title: Re: Confused about the best way to use sprites in my sprite collection
Post by: unikronsoftware on August 01, 2014, 09:07:52 am
tk2d uses a different workflow to Unity sprites. The sprite in tk2d is defined as a collection and index, so you create a sprite and assign the sprite you need. If you want to instantiate a particular sprite type, you can instantiate a prefab, then SetSprite("name"); Its much neater, and you dont need to assign thousands of sprite connections as you do with unity sprites.
Title: Re: Confused about the best way to use sprites in my sprite collection
Post by: negative_zero on August 04, 2014, 08:44:46 pm
I'm having a bit of trouble wrapping my head around this.

So far, I have been using Unity's system to take a spritesheets and chop it up into sprites, then then take each of those sprites, attach a bit of code to them and turn them all into prefabs.  Separate from that, I have 2dtk pull the same spritesheet into a sprite collection, and I use that sprite collection to create a tile map that I can design my stages with.  My final step is to go to the "data" part of the 2dtk tile map and connect the prefabs I made in Unity to the corresponding tiles, so I can design the stages with my actual prefabs.

This works, but I'm trying to move away from using Unity's system to deal with the spritesheets / sprites.  Ideally I want to just manage my spritesheet in a 2dtk sprite collection and use those pieces to create my prefabs.

I guess I'm just struggling figuring out the easiest way to use 2dtk to create all of those prefabs that I will be linking into the "data" part of the tile map.  If I understand what you're saying (and I'm not sure that I do), I would create a spriteless prefab and then determine which sprite gets attached to it with SetSprite("name"), or something along those lines?  And to get all 100 prefabs, I'd need to do that 100 times?  Or am I missing something easier here?

Is there a tutorial on SetSprite anywhere?
Title: Re: Confused about the best way to use sprites in my sprite collection
Post by: unikronsoftware on August 04, 2014, 10:17:10 pm
Why do you need to create the all the little prefabs for the tilemap editor? Do the prefabs actually do something?