0

我正在尝试加载游戏的开始菜单,并且使用 CCMenuItemImage 添加了一个播放按钮。一切都很好。但是,当我尝试单击播放按钮时,我收到此错误消息。

013-08-18 13:38:46.091 PeevedPenguins-iOS [5169:c07] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[StartMenuLayer]:无法识别的选择器发送到实例 0x9e5b400”

我不知道我做错了什么,因为我的选择器已经定义好了。请帮帮我?我一直在努力弄清楚为什么 Xcode 会这样做

@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
4

1 回答 1

1

您使用选择器配置了一个菜单项nil[为清楚起见添加了换行符]:

CCMenuItemImage *menuBackground = [CCMenuItemImage
                                  itemWithNormalImage:@"menu-background-hd.png"
                                  selectedImage:@"menu-background-hd.png" 
                                  target:self
                                  selector:nil];
于 2013-08-18T20:51:11.550 回答