Curnelious
Curnelious

Reputation: 1

CCMenuItemImage button is not working

buttons and menu are on screen but nothing happen when buttons pushed:

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 is having : id sender .

whats wrong with this menus ?? it some how always has problems.

Upvotes: 4

Views: 2352

Answers (2)

David T.
David T.

Reputation: 23439

okay, i think i got it - >

where are you sticking that piece of code?

in the -(void)onEnter{ ??? if so, check that you called [super onEnter]. otherwise, you will have a lot of problems

secondly, if that's not working, then check to see if anything else is getting any touches, because your menu might be behind another layer

Upvotes: 3

Marine
Marine

Reputation: 1097

I tried with your code it works perfectly..... The I worked is as below you can refer the code..... I have changed the Images name to Icons which I had and the Single Selector Method it worked with all the 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");
 }

Upvotes: 0

Related Questions