Hello Guest

Author Topic: A Way to Combine Sprite Collections?  (Read 8115 times)

Jason RT Bond

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
A Way to Combine Sprite Collections?
« 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?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #1 on: August 09, 2012, 11:43:34 pm »
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.

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #2 on: August 12, 2012, 04:11:18 am »
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)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #3 on: August 13, 2012, 12:16:51 am »
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.

MooNiZZ

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #4 on: August 13, 2012, 12:28:36 am »
as long as it lowers the drawcalls into a single one, I'm happy :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #5 on: August 13, 2012, 12:34:57 am »
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.

Jason RT Bond

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #6 on: August 19, 2012, 03:41:42 pm »
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).

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #7 on: August 20, 2012, 10:05:12 am »
Noted. I'll probably write a sample which does this - its likely to be something people would want to modify.

Tochas

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #8 on: December 06, 2012, 06:34:43 pm »
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

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: A Way to Combine Sprite Collections?
« Reply #9 on: December 06, 2012, 07:23:15 pm »
Filtering will be in the 1.90. Already implemented, so it'll definitely be there unless some serious performance issues crop up somewhere.