views:

1465

answers:

3

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 Don't know how?

Thanks in advance for helping me.

Sagar

+2  A: 

Ok. Damn Simple.

I find it by R & D.

Texture2D *x=[[Texture2D alloc]initWithImage:[UIImage imageNamed:@"box-purple-dark.png"]];
[mainSprite setTexture:x];
sugar
A: 

hi couldnt find the setTexture method pls help.

tomz
You should ask question for that. How ever, in each sprite class object has a method for setting a texture. Here mainSprite is object of sprite class. Hope that would be helpful to u.
sugar
+3  A: 

@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

5upr1
Will someone answer this? Coz I need to know the answer. Thanks.
5upr1