0

从我的角度来看,这可能是一个使用错误,但我无法让 CCControlButton 在 hud 层内捕捉任何触摸。我以这种方式实现 HUD 层:http : //www.raywenderlich.com/4666/how-to-create-a-hud-layer-with-cocos2d 在主游戏层中,启用了触摸(self.touchEnabled = YES; )

在 hudlayer.m 本身中,我只是添加了一个新的 CCControlButton 作为子项。像这样的东西:

CCLabelTTF* titleRight = [CCLabelTTF labelWithString:@"→" fontName:@"Helvetica" fontSize:FONTSIZE];
titleRight.color = ccRED;
CCControlButton* buttonRight = [CCControlButton buttonWithLabel:titleRight backgroundSprite:[CCScale9Sprite spriteWithFile:@"switch-mask.png"]];
buttonRight.position = ccp(ORIGIN.x + SIZE.width, ORIGIN.y);
buttonRight.userObject = [NSValue valueWithCGPoint:ccp(1, 0)];
[buttonRight addTarget:self action:@selector(actionPan:) forControlEvents:CCControlEventTouchUpInside];
[self addChild:buttonRight];

使用用 CCMenu 创建的按钮是可行的。

4

0 回答 0