从图层中删除菜单时出现问题
当 touchesMove
函数被调用时,我添加了一个菜单:
CCMenuItemImage * resetPosition =[CCMenuItemImage 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];
然后在 reset
方法中,我删除了这个菜单:
- (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)]];
}
但是 myresetMenu
也不是已被删除。请协助我。
I have added a menu when touchesMove
fonction is been called as:
CCMenuItemImage * resetPosition =[CCMenuItemImage 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是否是答案,但您将 myrestmenu 添加到父级两次并重置仅将其删除一次。
not sure if this is the answer but ur adding myrestmenu to parent twice and reset is only removing it once.
将 CCMenu 作为变量添加到拥有它的类中,而不是创建它。然后您可以随时添加或删除它。因此,在您的界面文件中执行以下操作:
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:
我知道这并不完全是我问题的答案,但我已经以给定的方式实现了解决方案。
好吧,我通过以下方式实现了它:
并且在禁用的情况下使用透明的小按钮。
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:
And in case of disable a transparent small button is been used.