ios - CCButton 不调用方法

标签 ios cocos2d-iphone

在我的 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/

相关文章:

ios - 如何将 CCSprite 转换为 UIImage

ios - Firebase FSnapshotUtilities 由于在枚举时改变 NSMutableDictionary 而崩溃

ios - 如何将 iOS slider 值限制为整数?

objective-c - 未调用 UISwipeGestureRecognizer 方法?

iphone - 应用程序在 [scrollView removeFromSuperview] 上崩溃;

ios - 在 XCode 中使用加速度计模拟器

ios - 关闭 View Controller 而不级联到 Root View Controller

ios - 从模态视图返回后使用手势识别器关闭 UISearchBar 的键盘

ios - NSRoundBankers 没有按照 Apple 的记录工作

iphone - 如何计算等轴测图上两点之间的实际距离?