Hello Guest

Author Topic: Changing collection data at runtime  (Read 4174 times)

tjgillis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Changing collection data at runtime
« on: October 12, 2012, 07:23:29 pm »
Hey,
Here's what I'm attempting to do; I would like my mobile app to load one of three assets bundles when it starts (hi, med, low) and for my app to use those sprites. I've pieced together a method of doing this but I'm not very happy with it and was wondering if you had a better method.

What I'm doing is getting all the tk2dsprites on the stage and looping through them, saving their name, changing the collection data, calling Build() and setting the name back.  Like I said, it works but it's not the nicest thing the world.

Attached is a unity package example.

Thanks,
TJ

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Changing collection data at runtime
« Reply #1 on: October 12, 2012, 08:01:22 pm »
I'm not exactly sure of the reason you're doing this, but if it is for quality - I strongly suggest trying the 1.80 beta. It only does 1x and 2x sprites right now, but easily extended for higher quality (there isn't an interface to do it, you can change it in code or set it up in the inspector).

The way you're doing it, it will work, but the dependencies will be incorrect. So it'll actually load the ones you saved it  at startup, and you'll end up with 2 of them loaded at a time.

tjgillis

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Changing collection data at runtime
« Reply #2 on: October 12, 2012, 08:17:16 pm »
Ya, we're doing it for quality. I'm going to try the beta now but if the project maintainers don't approve the change what did you mean by the dependencies would be incorrect?

And in that sample, there are two loaded, but the idea I was playing with is I would turn all of them into assets bundles and delete the data and atlases from the project.

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Changing collection data at runtime
« Reply #3 on: October 12, 2012, 08:54:42 pm »
Each sprite contains a reference to a sprite collection data object. This needs to exist at runtime.
The sprite collection data object has a reference to a texture / material / etc.

As soon as your scene loads (before your code runs) this would have loaded in.
If you deleted this object from the project, the value would read as null.

How 1.80 works is it stores a dummy data object - when this gets initialized, it will automatically load the appropriate alternate version.