Open jonnyijapan opened 11 years ago
Did you find out whether this was an implementation issue or a bug? I am trying to do the same thing in Cocos2d-xna and it too seems that the HUD layer is not accepting touches for CCControlButtons. Either I'm doing it wrong or it's not supported.
Actually, I noticed that the CCControlButton created with a CCLabel and a CCNode for the background does work, but not when created only with a CCNode for the background. I guess the OnTap event is on the label so doesn't fire without it?
This might be a usage mistake from my side, but I can't get CCControlButton to catch any touches while inside a hud layer. I implement HUD layers this way: http://www.raywenderlich.com/4666/how-to-create-a-hud-layer-with-cocos2d In the main game layer, touches are enabled (self.touchEnabled = YES;)
Inside hudlayer.m itself I just add a new CCControlButton as child. Something like this:
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];
Using buttons created with CCMenu works.