CCMenuItemSprite CCLabelBM字体选择器不工作



我在使下面代码中的选择器工作时遇到问题。即使是日志也不会显示任何内容。我该如何解决这个问题?

-(void)displaySettingsMenuItems {
CCSprite *buttonHolder = [CCSprite spriteWithFile:@"buttonHolder.png"];
buttonHolder1.position = ccp(screenSize.width/2, screenSize.height/2);
[self addChild:buttonHolder z:ZPos];
CCMenuItemSprite *instructionsItemSprite = [CCMenuItemSprite itemWithTarget:self selector:nil];
CCLabelBMFont *instructionsLabelFont = [CCLabelBMFont labelWithString:@"instructions" fntFile:@"TestingFont.fnt"];
CCMenuItemLabel *instructionsItemLabel = [CCMenuItemLabel itemWithLabel:instructionsLabelFont target:self selector:@selector(instructionsLayer)];
instructionsLabelFont.position =ccp(screenSize.width/2, 0.99*screenSize.height/2);
[instructionsItemSprite addChild: instructionsItemLabel z:ZPos];
[self addChild:instructionsItemSprite z:ZPos];
}

选择器的方法:

-(void)instructionsLayer {
CCLOG(@"code is okay");
[[MenuManager sharedMenuManager] runWithPrePlayMenu:kInstructions];
}

您应该将instructionsItemLabel菜单项添加到CCMenu(而不是CCMenuItem),然后将菜单添加到场景中。CCMenu是菜单项(一个或多个)的占位符,并扩展了CCLayer类。它为嵌入的菜单项提供触摸处理,并在存在涉及特定菜单项的触摸事件时提供调用其菜单项的逻辑。

-(void)displaySettingsMenuItems {
    CCSprite *buttonHolder = [CCSprite spriteWithFile:@"buttonHolder.png"];
    buttonHolder.position = ccp(screenSize.width/2, screenSize.height/2);  // <- you had buttonHolder1 ivar 
    [self addChild:buttonHolder z:zPos];
    CCLabelBMFont *instructionsLabelFont = 
        [CCLabelBMFont labelWithString:@"instructions" fntFile:@"TestingFont.fnt"]; 
    CCMenuItemLabel *instructionsItemLabel = 
        [CCMenuItemLabel itemWithLabel:instructionsLabelFont 
                                target:self 
                              selector:@selector(instructionsLayer)];
    CCMenu *menu = [CCMenu menuWithTtems:instructionsItemLabel,nil];
    menu.position = buttonHolder.position;
    [self addChild:menu];
}

最新更新