I am using the sprite frame cache to upload plists,and sprite-sheets,to use for animation . i have 2 approaches to that and i am sure that one of them is wrong .
i have to load everything i can to cache at the start because it takes time, so at the start of the scene i load all what i need to the close future .(but now my cache is full! )
cache should stay as empty as i can , so i am loading to cache at the moment i start the animation (it takes some time isn't it ? i think it flicks my game ) , and remove it at the same moment i am done with it . (now cache is not full but i have to load/reload many times.)
do i have to take care to remove the unused sprites from cache every time ?
load to cache is :
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrameByName:@"stopAnim.plist"];
removing unused is :
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
i can see in my iPad that the system is trying to remove unused sprites and have problems. whats exactly the way to work ?
After lots of research , i came to some conclusions :
First , it do takes time to load the frames in real time (while the animation is starting) to the batchNode
, and in cases of big images (iPad) it sometimes freezing the scene .
So , in some cases like that ,you MUST load the images to cache at the init method to avoid that, because you have no other way,and this is why we have cache anyway :
[[CCTextureCache sharedTextureCache] addImage:@"the_heavy_image.png"];
and if this animation happens frequently , you don't want to clear it from the cache .
Other stuff should be cleared from cache if you dont use it
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
will clear from cache only the sprites that was removed from screen already.
its not enough to just clear the frames :
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
In other scenarios where sprites-sheets images are not that big, you can load them to the batchNode
at the moment the animation is starts, and remove them at the end .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With