I've a background in my app, but clicking on a button should change it and use a different one.

I cannot add all of them in the sharedTextureCache because each one has a size of >16MB in the cache, and I've 30 different backgrounds.

What's the best way for switching the background without a loading time? I don't want the user to wait when clicking that button.

Thanks

有帮助吗?

解决方案 3

The only way I managed to not slow down the app was with this line:

[_background setTexture: [[CCTexture2D alloc] initWithImage:...]]

When I try to use the shared Texture Cache, even asynchronously, the app slows down. :-O

其他提示

remove all unused data. or texture...

[[CCDirector sharedDirector] purgeCachedData];
[[CCTextureCache sharedTextureCache] removeAllTextures];
[CCTextureCache purgeSharedTextureCache];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
[CCSpriteFrameCache purgeSharedSpriteFrameCache];

If you know what background will be shown next, you can preload it beforehand. Each retina device can use about 100 megabytes of memory (about 5 spritesheets 2048x2048). In this case you begin to receive memory warnings but app will work stable. All preloads you can make asynchronously to shared texture cache. Just don't forget to clean up unused textures by calling

[[CCTextureCache sharedTextureCache] removeUnusedTextures];

to force unload of unnesessary textures.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top