0

I'm trying to load a start menu for a game, and I've added a play button using a CCMenuItemImage. Everything loads just fine. However, when I try to click on the play button, I get this error message.

013-08-18 13:38:46.091 PeevedPenguins-iOS[5169:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[StartMenuLayer ]: unrecognized selector sent to instance 0x9e5b400'

I don't know what I'm doing wrong since my selector is defined and all. Please help me out? I've been pulling my hair out trying to figure out why Xcode would do this

@interface StartMenuLayer ()

@end

@implementation StartMenuLayer

-(id) init
{
    if ((self = [super init]))
    {
        CCMenu *myMenu = [CCMenu menuWithItems: nil];

        CCMenuItemImage *menuBackground = [CCMenuItemImage itemWithNormalImage:@"menu-background-hd.png" selectedImage:@"menu-background-hd.png" target:self selector:nil];
        [myMenu addChild:menuBackground];

        CCMenuItemImage *menuPlayButton = [CCMenuItemImage itemWithNormalImage:@"button-hd.png" selectedImage:@"button-hd.png" target:self selector:@selector(playGame:)];
        menuPlayButton.position = ccp(0, 0);
        [myMenu addChild:menuPlayButton];

        CCMenuItemImage * menuItem3 = [CCMenuItemImage itemWithNormalImage:@"catapult-hd.png"
                                                             selectedImage: @"catapult-hd.png"
                                                                    target:self
                                                                  selector:@selector(doSomethingThree:)];
        [myMenu addChild: menuItem3];

        menuPlayButton.position = ccp(0,-83.5);

        [self addChild:myMenu];
    }

    return self;
}

-(void) playGame:(CCMenuItem *)sender
{
//    [[CCDirector sharedDirector] replaceScene: (CCScene*)[[GameLayer alloc] init]];
    NSLog(@"Play the game!");
}

- (void) doSomethingThree:(CCMenuItem *)sender
{
    NSLog(@"The third menu was called");
}

@end
Raymond Chan
  • 63
  • 1
  • 7

1 Answers1

1

You configured one of your menu items with a nil selector [line breaks added for clarity]:

CCMenuItemImage *menuBackground = [CCMenuItemImage
                                  itemWithNormalImage:@"menu-background-hd.png"
                                  selectedImage:@"menu-background-hd.png" 
                                  target:self
                                  selector:nil];
jlehr
  • 15,557
  • 5
  • 43
  • 45
  • Thanks man! Now my program doesn't crash. But now do you know how I can add the play button and the third menu item on TOP of the menu background? Now when I click the play button/third menu item the program thinks I'm clicking on the menu background :[ – Raymond Chan Aug 18 '13 at 21:15
  • Try submitting a separate question for that (if you haven't already) -- it's not really relevant to your original question. – jlehr Aug 19 '13 at 20:42