[英]removeSpriteFramesFromFile doesn't seem to work
I'm using CCScrollLayer. 我正在使用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.
但我不认为“removeSpriteFramesFromFile”方法效果很好。 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: 我相信你误解了那种方法的作用:
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:@"file.plist"];
It loads the sprite frames in the plist, then removes the CCSpriteFrame objects in that plist from the cache - if they are cached. 它在plist中加载精灵帧,然后从缓存中删除该plist中的CCSpriteFrame对象 - 如果它们被缓存。 It does NOT remove the texture, only the CCSpriteFrame objects!
它不会删除纹理,只删除CCSpriteFrame对象!
To remove a texture from the cache you need to call: 要从缓存中删除纹理,您需要调用:
[[CCTextureCache sharedTextureCache] removeTexture:tex];
You should know that a CCSpriteFrame object is a relatively light-weight object that consumes at most 64 Bytes of memory. 您应该知道CCSpriteFrame对象是一个相对轻量级的对象,最多消耗64字节的内存。 That is nothing compared to even a very small 32x32 texture with 16-bit color depth which uses 2048 Bytes of memory.
与使用20位字节内存的16位色深的非常小的32x32纹理相比,这没什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.