forquare
forquare

Reputation: 324

Cocos2d menu programming *without* images

Good evening all,

I'm trying to code a menu, but I keep getting

Thread 1: Program received signal: "SIGABRT".

My code is minimal at the moment, just trying to get it to work!

@implementation Menu

+(id)scene{
    CCScene *scene = [CCScene node];
    CCLayer *layer = [Menu node];
    [scene addChild:layer];
    return scene;
}

-(id)init{
    if((self = [super init])){
        CCLabelTTF *playLabel = [CCLabelTTF labelWithString:@"Play" fontName:@"Marker Felt" fontSize:40];
        CCMenuItemLabel *play = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(doPlay:)]; //This is where SIGABRT happens//

        menu = [CCMenu menuWithItems:play, nil];
        [self addChild:menu];
    }
    return self;
}

-(void)doPlay{
    CCLOG(@"doPLay");
}
@end

Any help would be greatly appreciated :) There seems to be quite little on coding menus without images.

Upvotes: 0

Views: 267

Answers (1)

CodeSmile
CodeSmile

Reputation: 64477

First order of business:

  1. Go to Build Settings
  2. Locate the compiler warning flag "Undeclared Selector"
  3. Set it to YES

This will catch a lot of similar errors, and I really don't understand why this setting isn't turned on by default in all Xcode projects.

Let me explain what your error is, it's easy to overlook without that warning enabled. The selector passed to menu item is this:

@selector(doPlay:)

The selector that's implemented is this:

-(void) doPlay
{
}

They don't match! The menu item is expecting a selector that takes one parameter, as denoted by the : (colon). Change selector to this:

@selector(doPlay)

You'll be fine. Next time, the compiler will warn you about that mishap.

Upvotes: 2

Related Questions