ioscocos2d-iphonecctexturecache

How to add CCTexture2D to CCTextureCache cocos2d


I have some encrypted images.. They are pretty heavy, so I want to preload them by adding them to CCTextureCache. However CCTextureCache does not accept CCTexture2D as a parameter.. What can I do?

CCTexture2D *img = [[[CCTexture2D alloc] initWithImage:[UIImage imageWithContentsOfEncryptedFile:path]] autorelease];

        [[CCTextureCache sharedTextureCache] addImage:img]; // not accepted!!

Solution

  • Two options:

    The latter option will cause a notable delay due to the save & load process. I'd recommend the first approach. Most of the code you need to write that function is already in CCTextureCache, I believe there may even be just the method you need that only needs to be made public in the interface.