2D Toolkit Forum
2D Toolkit => Support => Topic started by: Jason RT Bond on August 09, 2012, 11:33:04 pm
-
So I've found myself in a bit of a situation. I have a number of Sprite Collections with animations set up and instances of animated and non-animated sprites placed into levels for my project. BUT these Sprite Collections should ideally all be part of the same collection to save on draw calls.
Are there any features available in 2D Toolkit to take this existing data and combine it (creating a single, larger Sprite Collection with all the animations and instances pointing to it) so that work doesn't have to be re-done?
-
There isn't any automatic way to do this - everyone's needs will obviously be different and catering to all of them would be impractical. However, you should be able to write some code to handle this with relative ease - they are just GameObjects after all.
The core algorithm should be something like this:
1. Create new sprite collection
2. Copy parameters from sprite collection 1, append information from 2, 3, and so on. Build sprite collection.
3. Create new animation (or modify existing one) - you can duplicate an animation in the project window, which is really handy when you want to modify the original and not break any links to objects.
4. Remap all sprite indices by looking for them by name if names are unique, or if they aren't its a bit more complicated - you'll have to maintain a map to remap them.
Hope that helps. I've noted this request though. If anyone else thinks something like this will be useful (at least as a code sample) please let me know.
-
This would be really useful for structuring my sprites in different collections and combining them _before_ runtime (in the editor, extra loading time is a pain in the buttocks),
else if option is made possible to sort the order of collections added. A code example would be appreciated.
(I got no animations but tons of smaller sprites that i need to keep track of with alot of collections)
-
I can write sample code for this, but the problem will be that all your sprites will still be referring to the original sprite collections... I can't think of a way to definitively fix everything in one go.
-
as long as it lowers the drawcalls into a single one, I'm happy :)
-
What I mean is ultimately, all the different sprites will need to be changed somehow. Its easy enough to write as script to change everything in the actively loaded scene, but to support every combination of this will be very very complex - people could be doing all sorts with these sprites, eg. spawning via code, assetbundles, etc.
I'll look into this - not promising anything, but I will investigate a solution in due time.
-
I should note that my particular need for this was a one-time thing where I'd taken the wrong route in prepping sprite collections and wanted a quick way to combine them so I didn't have to repeat work. I've already dealt with my situation, though. Still, it might be a problem more people run into (especially if working with multiple people on a team, where I can imagine this happening a lot).
-
Noted. I'll probably write a sample which does this - its likely to be something people would want to modify.
-
Some thing like this would come in handy, for example on my current project I have 52 sprites for each character (probably will increase as we create more content) and we have 10 diferent characters.
for level design would its more easy and tidy to have one spriteCollection per character
but performance wise would be better to have one or two 4096x4096 sprite collections with all the characters sprites on them the downside would be to deal with 520+ dropdown when setting frame animations.
another solution (at least for me) would be to have the option to use instead the dropdown a popup a window and be able to filter items by name.
any thoughts on that? thanks in advance
-
Filtering will be in the 1.90. Already implemented, so it'll definitely be there unless some serious performance issues crop up somewhere.