0

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.

Jonny
  • 15,955
  • 18
  • 111
  • 232
  • I think I found out the reason for my problem. In the layer (HelloWorldLayer.m) I had it registered as targeted delegate, and in `ccTouchBegan` always returned YES, thus swallowing all touches. I changed it to return NO. Seems ok so far. – Jonny Mar 22 '13 at 09:16
  • Oh, then you should probably get away with it by settings the touch priority of the `CCControlButton` to `kCCMenuTouchPriority` (I forgot the exact name) – Mazyod Mar 22 '13 at 15:21

0 Answers0