从图层中删除菜单时出现问题

发布于 2024-11-14 23:09:09 字数 903 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风轻花落早 2024-11-21 23:09:09

不确定这是否是答案,但您将 myrestmenu 添加到父级两次并重置仅将其删除一次。

not sure if this is the answer but ur adding myrestmenu to parent twice and reset is only removing it once.

他不在意 2024-11-21 23:09:09

CCMenu 作为变量添加到拥有它的类中,而不是创建它。然后您可以随时添加或删除它。因此,在您的界面文件中执行以下操作:

@interface myLayerClass : CCLayer {
CCMenu *myMenu;
}   

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;
}   
清君侧 2024-11-21 23:09:09

我知道这并不完全是我问题的答案,但我已经以给定的方式实现了解决方案。

好吧,我通过以下方式实现了它:

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)]];
}

并且在禁用的情况下使用透明的小按钮。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文