cocos2d 帮助: CCMenuItem 未选中 'EXC_BAD_ACCESS'和 CCCallFunc

发布于 2024-12-17 08:38:09 字数 855 浏览 3 评论 0原文

我一直遇到 CCMenuItem 及其与 CCCallFunc 的计时问题。

基本上我得到了“EXC_BAD_ACCESS”

@ CCMenuItem 类的这一行

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    ...
    [selectedItem_ unselected]; // EXC_BAD_ACCESS
    [selectedItem_ activate];
    ...
}

似乎菜单项在触摸结束之前被释放。我使用 CCCallFunc 调用“removeThisSprite”方法,将其从父级中删除,

因此我调用的 CCMenuItem 序列的最后一个操作:

[CCCallFuncO actionWithTarget:self selector:@selector(removeThisSprite:) object: _currentButton]

removeThisSprite 方法如下:

CCMenuItemSprite2 *sender = nil;
sender.isEnabled = NO;

if ([_sender isKindOfClass:[CCMenuItemSprite class]]) {
    sender = _sender;
    [sender removeFromParentAndCleanup: YES];
}

这通常发生在玩家通过点击“垃圾邮件”屏幕时,但除非水龙头快速,否则不会发生。我正在制作的游戏很可能会发生这种情况。我猜测玩家按按钮太快会出现某种计时问题。

I've been having problems with CCMenuItem and its timing with CCCallFunc.

Basically I'm getting 'EXC_BAD_ACCESS'

@ this line of the CCMenuItem class

-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    ...
    [selectedItem_ unselected]; // EXC_BAD_ACCESS
    [selectedItem_ activate];
    ...
}

It seems the menu item is deallocated before the touch ends. I'm using CCCallFunc to call a 'removeThisSprite' method that removes it from the parent

so the last action of the CCMenuItem sequence I call:

[CCCallFuncO actionWithTarget:self selector:@selector(removeThisSprite:) object: _currentButton]

The removeThisSprite method is like this:

CCMenuItemSprite2 *sender = nil;
sender.isEnabled = NO;

if ([_sender isKindOfClass:[CCMenuItemSprite class]]) {
    sender = _sender;
    [sender removeFromParentAndCleanup: YES];
}

This generally happens when the player 'spams' the screen with taps, but doesn't happen unless the taps are rapid. Which is likely to occur with a game I'm making. I'm guessing there's some sort of timing issue going on with players pressing the button too fast.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

故事与诗 2024-12-24 08:38:09

您始终可以尝试延迟删除菜单项:

[self performSelector:@selector(removeMenuItem:) withObject:sender afterDelay:0.1f];

...

-(void) removeMenuItem:(id)sender
{
   if ([sender isKindOfClass:[CCMenuItemSprite class]])
   {
      [sender removeFromParentAndCleanup: YES];
   }
}

You can always try and delay the removal of the menu item:

[self performSelector:@selector(removeMenuItem:) withObject:sender afterDelay:0.1f];

...

-(void) removeMenuItem:(id)sender
{
   if ([sender isKindOfClass:[CCMenuItemSprite class]])
   {
      [sender removeFromParentAndCleanup: YES];
   }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文