在我的Cocos2d游戏中,我正在为CCScene添加一个暂停按钮。暂停按钮是一个 CCButton。问题是当我按下按钮时,不会调用该操作。我已经测试了主菜单上的按钮,它工作正常。我尝试使用control.block = ^(id sender),但它也没有用。我在初始化方法中调用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 文档。