Reputation: 2461
In my Cocos2d game I am adding a pause button to the CCScene. The pause button is a CCButton. The problem is that when my button is pressed the action isn't called. I have tested the button on the main menu and it work fine. I tried using control.block = ^(id sender) and it didn't work either. I am calling addPauseButton method in the init method. I'm wondering if the problem has to do with the physics node.
-(void)addPauseButton
{
CCSpriteFrame *pauseNormalImage = [CCSpriteFrame frameWithImageNamed:@"pause.png"];
CCSpriteFrame *pauseHighlightedImage = [CCSpriteFrame frameWithImageNamed:@"pause_selected.png"];
CCButton *btnPause = [CCButton buttonWithTitle:nil
spriteFrame:pauseNormalImage
highlightedSpriteFrame:pauseHighlightedImage
disabledSpriteFrame:nil];
btnPause.positionType = CCPositionTypeNormalized;
btnPause.position = ccp(0.85f, 0.85f);
[btnPause setTarget:self selector:@selector(onbtnPauseTapped:)];
[self addChild:btnPause z:10000];
}
- (void)onbtnPauseTapped:(id)sender
{
NSLog(@"Working?");
}
Upvotes: 1
Views: 61
Reputation: 6899
I had this same issue a while ago and couldn't figure it. The problem was a UIGestureRecognizer
preventing the user touch being sent up the responder chain. Check your code to see if you are using a UIGestureRecognizer
. I also recommend reading the Apple documentation for UIGestureRecognizer.
Upvotes: 2