Hello Guest

Author Topic: Moving a sprite to a different collection without affecting current objects  (Read 3048 times)

tibithegreat

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hi,

We've been using tk2d a lot in our game to display the art objects and we created a lot of collections to group the sprites so that it would be easier for level designers. However we are currently having some issues with memory. Investigating we figured that we were loading a lot of atlases for one or two small sprites (and the atlas contained a lot more sprites which were not used in the level). So we figured we should try moving the sprites around to stop this from happening (remove some of the redundant objects that we are loading). The problem at hand right now is this:

Can we move the sprites from one collection to another without affecting the current objects? From what I see tk2dsprite component stores the spriteid and uses that one for reference inside the collection.

The current idea I have to do this is to do a script which will rename the gameobjects using tk2dsprite and store the name of the sprite inside the gameobject's name, then we manually move the sprites around, and then try to see in which collection each sprite ended up and update the objects. However before I do this I would like to know if there isn't a better way to do this.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
The best way to do this it something like you've planned -
1. Add sprite to new collection
2. Find all tk2dBaseSprite derived objects, check the CurrentSprite, if matches the one we're changing, switch the collection and spriteId (SetSprite(collection, name))
3. Repeat for all scenes, and don't forget prefabs
4. Remove sprite form old collection.