在我的 Cocos2d 游戏中,我向 CCScene 添加了一个暂停按钮。暂停按钮是一个 CCButton。问题是当按下我的按钮时,不会调用操作。我已经测试了主菜单上的按钮,它工作正常。我尝试使用 control.block = ^(id sender) 但它也没有用。我在 init 方法中调用 addPauseButton 方法。我想知道问题是否与物理节点有关。
-(void)addPauseButton
{
CCSpriteFrame *pauseNormalImage = [CCSpriteFrame frameWithImageNamed:@"pause.png"];
CCSpriteFrame *pauseHighlightedImage = [CCSpriteFrame frameWithImageNamed:@"pause_selected.png"];
CCButton *btnPause = [CCButton buttonWithTitle:nil
spriteFrame:pauseNormalImage
highlightedSpriteFrame:pauseHighlightedImage
disabledSpriteFrame:nil];
btnPause.positionType = CCPositionTypeNormalized;
btnPause.position = ccp(0.85f, 0.85f);
[btnPause setTarget:self selector:@selector(onbtnPauseTapped:)];
[self addChild:btnPause z:10000];
}
- (void)onbtnPauseTapped:(id)sender
{
NSLog(@"Working?");
}
最佳答案
我前段时间遇到了同样的问题,但无法弄清楚。问题是 UIGestureRecognizer
阻止了用户触摸被发送到响应链。检查您的代码,看看您是否正在使用 UIGestureRecognizer
。我还建议阅读有关 UIGestureRecognizer 的 Apple 文档.
关于ios - CCButton 不调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27339215/