user123
user123

Reputation: 2721

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!!

Upvotes: 0

Views: 385

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

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.

Upvotes: 1

Related Questions