cocos2d 帮助: CCMenuItem 未选中 'EXC_BAD_ACCESS'和 CCCallFunc
我一直遇到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您始终可以尝试延迟删除菜单项:
You can always try and delay the removal of the menu item: