[英]CCButton not calling method
In my Cocos2d game I am adding a pause button to the CCScene. 在我的Cocos2d游戏中,我向CCScene添加了一个暂停按钮。 The pause button is a CCButton.
暂停按钮是CCButton。 The problem is that when my button is pressed the action isn't called.
问题在于,当按下我的按钮时,不会调用该动作。 I have tested the button on the main menu and it work fine.
我已经测试了主菜单上的按钮,它工作正常。 I tried using control.block = ^(id sender) and it didn't work either.
我尝试使用control.block = ^(id sender),但它也不起作用。 I am calling addPauseButton method in the init method.
我在init方法中调用addPauseButton方法。 I'm wondering if the problem has to do with the physics node.
我想知道问题是否与物理节点有关。
-(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?");
}
I had this same issue a while ago and couldn't figure it. 前一段时间我也遇到过同样的问题,无法解决。 The problem was a
UIGestureRecognizer
preventing the user touch being sent up the responder chain. 问题是
UIGestureRecognizer
阻止了用户触摸被发送到响应链。 Check your code to see if you are using a UIGestureRecognizer
. 检查您的代码以查看是否正在使用
UIGestureRecognizer
。 I also recommend reading the Apple documentation for UIGestureRecognizer . 我还建议阅读有关UIGestureRecognizer的Apple文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.