How to remove sprite in cocos2d?
In cocos2d
I created SPRITE
but after click on menu Button I want to remove sprite.
this is sprite code..
// create and initialize our seeker sprite, and add it to this layer
seeker1 = [CCSprite spriteWithFile: @"button_Red.png"];
seeker1.position = ccp( 50, 150 );
[self addChild:seeker1];
And also I create menu.
CCMenuItemImage * menuItem1 = [CCMenuItemImage itemFromNormalImage:@"1.gif"
selectedImage: @"2.gif"
target:self
selector:@selector(doSomethingOne:)];
And This is remove code so what I done wrong in Remove.
- (void) doSomethingOne: (CCMenuItem *) menuItem
{
NSLog(@"The first menu was called");
[self.children removeObject:s开发者_运维知识库eeker1];// removeSpriteFrames:seeker1 removeChild:seeker1 cleanup:YES];
}
Please give me code for how to remove sprite.
Try
[seeker1 removeFromParentAndCleanup:YES];
Instead of
[self.children removeObject:seeker1];
use
[self removeChild:seeker1 cleanup:YES];
As you are adding child to self
, then how can you remove it from self.children
精彩评论