problem in removing menu from layer
I have added a menu when touchesMove
fonction is been called as:
CCMenuItemImage * resetPosition =[CCMenuItemIma开发者_Python百科ge itemFromNormalImage:@"position.png" selectedImage: @"position_over.png" target:self
selector:@selector(reset:)];
resetPosition.position =ccp(400, 300);
myresetMenu = [CCMenu menuWithItems:resetPosition, nil];
myresetMenu.position = ccp(0,0);
[[self parent] addChild:myresetMenu z:10];
menuWithItems:resetPosition, nil];
And then in reset
method i have removed this menu as:
- (void) reset: (CCMenuItem *) menuItem
{
[self unschedule:@selector(reset:)];
[[self parent] removeChild:myresetMenu cleanup:YES];
[[SimpleAudioEngine sharedEngine] playEffect:@"btn_click.mp3"];
[self.parent runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/650) position:ccp(0,0)]];
}
but myresetMenu
is nor been removed. please assist me with it.
not sure if this is the answer but ur adding myrestmenu to parent twice and reset is only removing it once.
Add CCMenu as a variable to the class that owns it instead of creating it. Then you can add or remove it whenever you like. So in your interface file do something like:
@interface myLayerClass : CCLayer {
CCMenu *myMenu;
}
I know this is not exactly the answer of my question, but i have achieved the solution in given way.
Well I have implemented it by the following way:
if(diffX > 0)
{
[resetPosition runAction:[CCMoveTo actionWithDuration:round(-(-3112-self.parent.position.x)/650)
position:ccp((3112+self.position.x+400),resetPosition.position.y)]];
}
else
{
[resetPosition runAction:[CCMoveTo actionWithDuration:(-self.parent.position.x/650)
position:ccp(400,resetPosition.position.y)]];
}
- (void) reset
{
CCLOG(@"reset Method Called");
[self.parent stopAllActions];
[resetPosition setIsEnabled:NO];
[resetPosition stopAllActions];
[[SimpleAudioEngine sharedEngine] playEffect:@"btn_click.mp3"];
[resetPosition runAction:[CCMoveTo actionWithDuration:.09f
position:ccp(400,300)]];
[self.parent runAction:[CCMoveTo actionWithDuration:.09f position:ccp(0,0)]];
}
And in case of disable a transparent small button is been used.
精彩评论