Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 397
Sagar Kothari Avatar asked Oct 13 '09 21:10

Sagar Kothari


2 Answers

@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

like image 121
5upr1 Avatar answered Nov 03 '22 04:11

5upr1


Ok. Damn Simple.

I find it by R & D.

Texture2D *x=[[Texture2D alloc]initWithImage:[UIImage imageNamed:@"box-purple-dark.png"]];
[mainSprite setTexture:x];
like image 3
Sagar Kothari Avatar answered Nov 03 '22 03:11

Sagar Kothari