替换sprite中的图片——iPhone的cocos2d游戏开发游戏开发、图片、sprite、cocos2d

2023-09-06 09:54:51 作者:空有执念了残生

我想改变精灵图像.

比如说:

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

在这里,Sprite 已经添加到图层中.我有可以访问它的 mainSprite(指针).

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

如果我改变了

[mainSprite setOpacity:150];

完美运行.但是这里我想改变精灵图像而不是不透明度.

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

但我不知道怎么做.

推荐答案

@sagar:在 cocos2d 0.99.x 我使用

@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