CCMenuItemImage button not working

Buttons and menus

are on the screen, but nothing happens when the buttons are pressed:

CCMenuItemImage *menuB = [CCMenuItemImage itemFromNormalImage:@"menuB.png" selectedImage:@"menuB.png" target:self selector:@selector(goMenu:)]; CCMenuItemImage *tryAgainB = [CCMenuItemImage itemFromNormalImage:@"tryAgainB.png" selectedImage:@"tryAgainB.png" target:self selector:@selector(tryAgain:)]; CCMenuItemImage *menuGoodByeT = [CCMenuItemImage itemFromNormalImage:@"menu.png" selectedImage:@"menu.png" target:self selector:@selector(nothing:)]; menuB.position=ccp(-65,-40); tryAgainB.position=ccp(15,-40); menu = [CCMenu menuWithItems:menuGoodByeT,menuB,tryAgainB, nil]; menu.isTouchEnabled = YES; [self addChild: menu]; 

yes, the method has: id sender .

What is wrong with this menu? these are some, as always there are problems.

+4
source share
2 answers

ok, i think i got it →

where do you stick to this piece of code?

in -(void)onEnter{ ??? if so, be sure to call [super onEnter] . otherwise you will have a lot of problems.

secondly, if this does not work, then check if anything else has happened, because your menu may be behind another layer

+3
source

I tried with your code, it works fine ..... I worked as shown below, you can link to the code ..... I changed the name of the "Image" to the "Icons" that I had, and the method Single Selector he worked with all three methods.

 -(id) init { if((self = [super init])) { CGSize winSize = [CCDirector sharedDirector].winSize; self.isTouchEnabled = YES; CCMenuItemImage *menuB = [CCMenuItemImage itemFromNormalImage:@"Icon-72.png" selectedImage:@"Icon-72.png" target:self selector:@selector(goMenu:)]; // Changed the Images and Selector Method CCMenuItemImage *tryAgainB = [CCMenuItemImage itemFromNormalImage:@"Icon-72.png" selectedImage:@"Icon-72.png" target:self selector:@selector(goMenu:)]; CCMenuItemImage *menuGoodByeT = [CCMenuItemImage itemFromNormalImage:@"Icon-72.png" selectedImage:@"Icon-72.png" target:self selector:@selector(goMenu:)]; menuB.position=ccp(-65,-40); tryAgainB.position=ccp(15,-40); CCMenu * menu = [CCMenu menuWithItems:menuGoodByeT,menuB,tryAgainB, nil]; menu.isTouchEnabled = YES; [self addChild: menu]; } return self; } -(void) goMenu:(id) sender { NSLog(@"Go menu pressed"); } 
0
source

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


All Articles