I’ve got a pause button in my game, in fact it is just a CCSprite:
_pauseButton = [[CCSprite spriteWithFile:@"pauseButton.png"] retain];
_pauseButton.position = ccp(_winSize.width * 0.92, _winSize.height * 0.1);
[self addChild:_pauseButton];
And on press I wanna pause the game and switch pausebutton’s image to @”playButton.png”.
I know 2 ways for doing that:
- Making a batchnode and adding those 2 images (pauseButton.png and playbutton.png) to sprite cash, so i can switch it via animation.
- Recreating sprite
Code:
[_pauseButton removeFromParentAndCleanup:YES];
[_pauseButton release];
_pauseButton = [[CCSprite spriteWithFile:@"playButton.png"] retain];
_pauseButton.position = ccp(_winSize.width * 0.92, _winSize.height * 0.1);
[self addChild:_pauseButton];
Are there any “proper” and easier ways to do this, or should I use 1 of those I mentioned above?
if you use a texture atlas you can use setDisplayFrame: to change what the sprite displays. That’s the most efficient way.
Otherwise you’ll have to use setTexture: to change the texture the sprite uses.