CCControlExtension icon indicating copy to clipboard operation
CCControlExtension copied to clipboard

CCControlButton does not catch touches when in hud layer

Open jonnyijapan opened this issue 12 years ago • 2 comments

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.

jonnyijapan avatar Mar 13 '13 02:03 jonnyijapan

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.

Arkiliknam avatar Jul 11 '14 13:07 Arkiliknam

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?

Arkiliknam avatar Jul 11 '14 14:07 Arkiliknam