I’m using CCScrollLayer. and I’m trying to prepare a level’s texture at the stage select screen before level is started.
So, I made this screen as when I change level, then before level’s textured that was prepared is supposed to be removed. But I don’t think “removeSpriteFramesFromFile” method work well. because when I scroll the several layer, It suddenly call “Memory warning” and remove that textures at that late time then I expected.
-(void) prepareTexture:(NSNumber*)number
{
int _page = [number intValue];
if(loadingTexNum != 0 && (_page + 1) != loadingTexNum)
{
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:[NSString stringWithFormat:@"L%d.plist", loadingTexNum]];
loadingTexNum = _page + 1;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"L%d.plist", loadingTexNum]];
}
if(loadingTexNum == 0 && (_page + 1) != loadingTexNum)
{
loadingTexNum = _page + 1;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"L%d.plist", loadingTexNum]];
}
}
Thanks
I believe you misunderstood what that method does:
It loads the sprite frames in the plist, then removes the CCSpriteFrame objects in that plist from the cache – if they are cached. It does NOT remove the texture, only the CCSpriteFrame objects!
To remove a texture from the cache you need to call:
You should know that a CCSpriteFrame object is a relatively light-weight object that consumes at most 64 Bytes of memory. That is nothing compared to even a very small 32×32 texture with 16-bit color depth which uses 2048 Bytes of memory.