Cocos2d CCMenuItem目标给出了SIGABRT

时间:2011-07-21 11:23:18

标签: iphone xcode cocos2d-iphone

我正在尝试创建一个菜单系统,根据按下的内容调用方法。问题是当我向CCMenuitems添加目标和选择器时,它会因sgabrt错误而崩溃。我知道问题与目标有关,但它应该是什么?这是我的.h和.m代码

#import "cocos2d.h"

// splashMenuLayer
@interface splashMenuLayer : CCLayer
{
BOOL menuButtonsShowing;
CCLabelTTF * splashLabel;
CCMenuItemFont * puzzleMenuItem;
CCMenuItemFont * raceMenuItem;
CCMenuItemFont * leaderboardMenuItem;
CCMenu * mainMenu;
}

// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
-(void) ccTouchEnded:(NSSet *)touches withEvent:(UIEvent *)event;
-(void) deleteLabel :(id)sender;
-(void) puzzleMode:(id)sender;
-(void) raceMode:(id)sender;
-(void) Leaderboard:(id)sender;

@property BOOL menuButtonsShowing;
@property (nonatomic, retain) CCLabelTTF* splashLabel;
@property (nonatomic, retain) CCMenuItem* puzzleMenuItem;
@property (nonatomic, retain) CCMenuItem* raceMenuItem;
@property (nonatomic, retain) CCMenuItem* leaderboardMenuItem;
@property (nonatomic, retain) CCMenu* mainMenu;

@end

最后

-(void) ccTouchEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if (menuButtonsShowing == NO) {
    id action = [CCSequence actions:[CCFadeOut actionWithDuration:0.5],[CCCallFunc actionWithTarget:self selector:@selector(deleteLabel:)], nil];
    [splashLabel runAction:action];

//create the menu items and all the target/selector
    puzzleMenuItem = [CCMenuItemFont itemFromString:@"Puzzle Mode" target:self selector:@selector(puzzleMode:)];
    raceMenuItem = [CCMenuItemFont itemFromString:@"Race Mode" target:self selector:@selector(raceMode:)];
    leaderboardMenuItem = [CCMenuItemFont itemFromString:@"Leaderboard" target:self selector:@selector(leaderboard:)];

//add the menu items to the menu
    mainMenu = [CCMenu menuWithItems:puzzleMenuItem, raceMenuItem, leaderboardMenuItem, nil];
    [mainMenu alignItemsVertically];
    mainMenu.position = ccp(240, 100);


    [self addChild:mainMenu];
    }
}

-(void) puzzleMode:(id)sender{
NSLog(@"lol1");
}
-(void) raceMode:(id)sender{
    NSLog(@"lol2");
}
-(void) Leaderboard:(id)sender{
    NSLog(@"lol3");

}

2 个答案:

答案 0 :(得分:2)

使用大写L

更正此行
leaderboardMenuItem = [CCMenuItemFont itemFromString:@"Leaderboard" target:self selector:@selector(leaderboard:)];

     leaderboardMenuItem = [CCMenuItemFont itemFromString:@"Leaderboard" target:self selector:@selector(Leaderboard:)];

答案 1 :(得分:1)

我唯一能够发现的是@selector(leaderboard:)应为@selector(Leaderboard:)(大写)。

麦克