Reputation: 780
In cocos2d 2.x we change the image of a CCSprite using CCTexture. But in cocos2d 3.x CCTextureCache seems to be deprecated as Xcode warns me : "undeclared identifier 'CCTextureCache'". Or may be am I miss something as I'm new to cocos.
So how can we change the image of a CCSprite in v3 ??
Thank you.
Upvotes: 3
Views: 6492
Reputation: 780
I think I know how to do.
Some code :
3) We put in cache
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"monsterSpriteSheet.plist"];
4) We create the sprite
CCSprite * mySprite = [CCSprite initWithSpriteFrame: [CCSpriteFrame frameWithImageNamed: @"monster_01.png"]];
5) To change image :
[mySprite setSpriteFrame:[CCSpriteFrame frameWithImageNamed: @"monster_02.png"]];
This works perfectly with cocos2d v3.
I spent 6 hours to have this process. Sometimes I feel stupid.
Upvotes: 8
Reputation: 2778
You can do it by using this
CCSpriteFrameCache and after that you can change you sprite by using function setSpriteFrame of ccsprite.
Upvotes: 0