Hello Guest

Author Topic: Sprite Collections proper practices  (Read 3908 times)

axelucho

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Sprite Collections proper practices
« on: August 14, 2013, 03:41:06 pm »
Hi, so i'm just getting into 2dtk, and I am actually migrating from another 2dtoolkit so i'm still figuring things out.
I was having doubts regarding collections. I currently need to change some sprites collections during runtime, but it seems 2dtk doesnt have any quick reference for me to access (at least i didnt find any). So i went ahead and made the collections i'm interested in loadable and in a public class of mine did the following:

tk2dSpriteCollectionData allSpriteCollections = Resources.FindObjectsOfTypeAll(typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData[];

But the results i'm obtaining are... confusing:


I'm obtaining LavaCollection (which is not even on the resources folder, and it NOT set to loadable) instead of FallingRockCollection. Any thoughts?

Regardless of my problem I would like to know if the way im sorting things out is ok, or if i should be doing things differently regarding this issue.

Thanks in advance!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Collections proper practices
« Reply #1 on: August 14, 2013, 08:09:07 pm »
You can't really do Resources.FindObjectsOfTypeAll as it does NOT find things that are loadable, just things that are loaded for some reason or other. If you need to change collections at runtime, your best bet is to use the resources folder (only the sprite collection data object), and then use Resources.Load to load what you need.

There isn't officially an "index" of loadable sprite collections anywhere, but you could probably use the undocumented "loadable sprite collection" feature if you are feeling lucky :) Check tk2dSystem.cs for more details - it does maintain an index internally of things marked as loadable, but it isn't public because the public API isn't fully tested.

axelucho

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Sprite Collections proper practices
« Reply #2 on: August 15, 2013, 04:33:03 pm »
Thanks for the reply, for now i'll stick to using resources.load, i'll look into tk2dsystem when I get  a chance though.
Cheers!