CCMenuItemImage not responding to touches!
So I am adding a CCMenuItemImage to my layer like so:
CCMenuItemImage *pauseButton = [CCMenuItemImage itemFromNormalImage:@"pausebutton.png"
selectedImage:@"pausebutton.png" // TODO add selected image
disabledImage:@"pausebutton.png"
target:self
selector:@selector(pauseGame:)];
pauseButton.position = ccp(24, 292);
[self addChild:pauseButton];
The problem is my pauseGame: selector is never triggered w开发者_Go百科hen I touch the pause button!
I have verified that the selector is set properly by doing a [pauseButton activate] (calls the selector).
Also, I have verified that my layer is responding to touches by outputting logging information in ccTouchesBegan and ccTouchesEnded.
It is also worth noting that I have sprites in my layer which register themselves for touches like so:
- (void) onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
[super onEnter];
}
What could the problem be?
Hmm... You didnt add to a CCMenu...
CCMenu* menu = [CCMenu menuWithItems:pauseButton, nil];
menu.isTouchEnabled = YES;
[self addChild:menu];
Note that your pausegame should be:
-(void)pauseGame:(id)sender
{
//pause game!!!
}
精彩评论