CCMenuItemImage does not respond to touch!

So, I am adding CCMenuItemImage to my layer, for example:

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: the selector never fires when I touch the pause button!

I checked that the selector is set correctly by executing [pauseButton activate] (invokes the selector).

In addition, I confirmed that my layer responds to touches by displaying registration information in ccTouchesBegan and ccTouchesEnded.

It is also worth noting that I have sprites in my layer that are registered for such touches:

- (void) onEnter
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
    [super onEnter];
}

What is the problem?

+3
source share
1 answer

Hmm ... you have not added 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!!!
}
+2
source

Source: https://habr.com/ru/post/1796195/


All Articles