Question

Question is simple as the tip of this thread.
Generating a new imagefile with same name but with different content.
Im sure that file is generated from scratch.(checking with iexplorer and can see that new image with
new content is generated)but somehow CCsprite loads the first generated file with same name.
Not sure if CCspriteFrame caches it.
purgeSharedSpriteCache or removeUnusedSpriteFrames doesnt removes it (if it is)
so what do you prefer for me ?

{
  NSArray *docs=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *docPath=[docs objectAtIndex:0];
  NSString *fn=[docPath stringByAppendingPathComponent:@"tmp.png"];



  if([[NSFileManager defaultManager]fileExistsAtPath:fn])
  {
    //[CCSpriteFrameCache purgeSharedSpriteFrameCache];
    //[[CCSpriteFrameCache sharedSpriteFrameCache]removeUnusedSpriteFrames];
    //[[CCSpriteFrameCache sharedSpriteFrameCache]removeSpriteFrames];
    CCSprite *firstSprite=[CCSprite spriteWithFile:fn];
    [self regenerateNewTmpPng];//this deletes old tmp.png and generates imagefile with same name but different content
    CCSprite *secondSprite=[CCSprite spriteWithFile:fn];//this loads same content as squareSprite
  }
}
Was it helpful?

Solution

the CCSprite ctor you are using does check for the texture in the cache first. If it finds it in cache, it returns a new ccsprite with the cached object. If not, it puts it in the cache (silently) and returns the ccsprite with the newly cached texture.

If you want to you could remove the texture first from the cache

CCSprite *firstSprite=[CCSprite spriteWithFile:fn];
[self regenerateNewTmpPng];
[[CCTextureCache sharedTextureCache] removeTextureWithKey:@"tmp.png"];
CCSprite *secondSprite=[CCSprite spriteWithFile:fn];

ob cit. cocos2d 2.0, not tested, but should work.

OTHER TIPS

Try to remove the texture from the cache before loading the new CCSprite : https://github.com/cocos2d/cocos2d-iphone/blob/develop-v2/cocos2d/CCTextureCache.m#L412

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top