I am new to Cocos2D. I am making a simple game for iPhone in which I want my sprite to disappear with some animation. Till now I can make it disappear with the following code:-
-(void)selectSpriteForTouch:(CGPoint)touchLocation
{
for (CCSprite *sprite in targets)
{
if (CGRectContainsPoint(sprite.boundingBox, touchLocation))
{
NSLog(@"sprite was touched");
[sprite.parent removeChild:sprite cleanup:YES];
[[SimpleAudioEngine sharedEngine] playEffect:@"pop.wav"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:4.0f];
}
}
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches )
{
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
[self selectSpriteForTouch:location];
NSLog(@"touch was detected");
}
}
Now I want the sprite to disappear with some animation or any effect. How can I do so?
As an example, this would make your sprite shrink until it disappears then remove it from it’s parent:
For other actions, try
CCMoveToorCCJumpToorCCRotateBy. You can run several actions at once, so above therunAction:line I provided, try another[sprite runAction:[CCRotateBy actionWithDuration:0.4 angle:360]]