Reputation: 1212
I am making a game in cocos2d. I am checking the level of the sprite and updating the texture accordingly. Now at start the image is placed in hd alright.. now when the game starts and i start moving the sprite the hd image is replaced with the normal one. I am checking the replacing the texture with this code.
int value = [self.weapon.weaponLevel intValue];
NSString *path = [[NSBundle mainBundle]pathForResource:@"name" ofType:@"png"];
UIImage *imageView = [[UIImage alloc]initWithContentsOfFile:path];
CCTexture2D *frame = [[CCTexture2D alloc]initWithImage:imageView];
[self.player setTexture:frame];
Can any one please help me out here. Thanks. regards.
Upvotes: 0
Views: 146
Reputation: 19164
There's no need to go through NSBundle
and UIImage
when you can use CCTextureCache
that handles all the path resolution and HD/SD detection internally.
Plus, as the name implies, it caches the texture so that the subsequent use of the same sprite file would be faster:
Here is what you need:
CCTexture2D *frame = [[CCTextureCache sharedTextureCache] addImage:@"name.png"];
[self.player setTexture:frame];
Upvotes: 2