Search code examples
xcodecocos2d-iphonesprite

Replacing image in sprite - cocos2d game development of iPhone


I want to change the sprite image.

Say for example:

mainSprite=[Sprite spriteWithFile:@"redFile.png"];
[self addChild:mainSprite];

Here, Sprite is already added to a layer. I have mainSprite (pointer) which can access it.

If I change

[mainSprite setOpacity:150];

it works perfectly. But here I want to change the sprite image instead of opacity.

But I don't know how.


Solution

  • @sagar: In cocos2d 0.99.x I use

    [sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"sprite.png"]];
    

    It works. The next question is, how can I get back to my previous sprite? Thanks