Question

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!!
Was it helpful?

Solution

Two options:

  • add a method to cache CCTexture2D* objects with a key (unique string)
  • save the UIImage to disk (in Application Support directory), then load it as normal with cocos2d

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.

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