2012-07-19 42 views
0

所以我一直在嘗試爲我開發的遊戲創建一個菜單。 我正在使用Cocos2d,遊戲是以縱向設置的。我寫的menu.m文件看起來像這樣。NSInvocation錯誤

// Import the interfaces 
#import "Menu.h" 
#import "BankerInfo.h" 

// HelloWorldLayer implementation 
@implementation MenuLayer 

+(CCScene *) scene 
{ 
    // 'scene' is an autorelease object. 
    CCScene *scene = [CCScene node]; 

// 'layer' is an autorelease object. 
MenuLayer *layer = [MenuLayer node]; 

// add layer as a child to scene 
[scene addChild: layer]; 

// return the scene 
return scene; 
} 

// on "init" you need to initialize your instance 
-(id) init 
{ 
// always call "super" init 
// Apple recommends to re-assign "self" with the "super" return value 
if((self=[super init])) { 

    // ask director the the window size 
    CGSize winSize = [[CCDirector sharedDirector] winSize]; 

    CCSprite *menubackground = [CCSprite spriteWithFile:@"Ninja Menu Background.png"]; 
    menubackground.position = ccp(winSize.width/2, winSize.height/2); 
    [self addChild:menubackground z:-1]; 


    CCLabelTTF *title = [CCLabelTTF labelWithString:@"Catch It If You Can!"    fontName:@"Zapfino" fontSize:22]; 
    title.position = ccp(160, 420); 
    [self addChild: title]; 

    CCLayer *menuLayer = [[CCLayer alloc] init]; 
    [self addChild:menuLayer]; 

    CCMenuItem *Bankerbutton = [CCMenuItemImage 
           itemFromNormalImage:@"Bankernotpressed.png" 
           selectedImage:@"Bankerpressed.png" 
           target:self 
           selector:@selector(startBanker:)]; 
    //Bankerbutton.position = ccp(100, 175); 

    CCMenuItem *Babybutton = [CCMenuItemImage 
           itemFromNormalImage:@"Babynotpressed.png" 
           selectedImage:@"Babypressed.png" 
           target:self 
           selector:@selector(startBaby:)]; 
    //Babybutton.position = ccp(100, 75); 
    CCMenuItem *Mommaduckbutton = [CCMenuItemImage 
           itemFromNormalImage:@"Mommaducknotpressed.png" 
           selectedImage:@"Mommaduckpressed.png" 
           target:self 
           selector:@selector(startMommaduck:)]; 
    //Mommaduckbutton.position = ccp(350, 175); 
    CCMenuItem *Baseballbutton = [CCMenuItemImage 
           itemFromNormalImage:@"Baseballnotpressed.png" 
           selectedImage:@"Baseballpressed.png" 
           target:self 
           selector:@selector(startArcher:)]; 
    //Baseballbutton.position = ccp(350, 75); 
    CCMenuItem *Newtonbutton = [CCMenuItemImage 
            itemFromNormalImage:@"Newtonnotpressed.png" 
            selectedImage:@"Newtonpressed.png" 
            target:self 
            selector:@selector(startArcher:)]; 
    //Newtonbutton.position = ccp(350, 75); 

    CCMenu *menu = [CCMenu menuWithItems: Bankerbutton, Babybutton, Mommaduckbutton,   Baseballbutton, Newtonbutton, nil]; 
    menu.position = ccp(winSize.width/2, (winSize.height/2)-30); 
    [menu alignItemsInRows: 
    [NSNumber numberWithInt:2], [NSNumber numberWithInt:2], nil]; 
    [menuLayer addChild: menu]; 

} 
return self; 
} 

- (void) startBanker: (id) sender 
{ 
[[CCDirector sharedDirector] replaceScene:[BankerInfoLayer scene]]; 
} 
/*- (void) startBaby: (id) sender 
{ 
[[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Soldier scene]]; 
} 
- (void) startMommaduck: (id) sender 
{ 
[[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Mage scene]]; 
} 
- (void) startBaseball: (id) sender 
{ 
[[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Archer scene]]; 
} 
- (void) startNewton: (id) sender 
{ 
[[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Archer scene]]; 
} 
*/ 
// on "dealloc" you need to release all your retained objects 
- (void) dealloc 
{ 
// in case you have something to dealloc, do it in this method 
// in this particular example nothing needs to be released. 
// cocos2d will automatically release all the children (Label) 

// don't forget to call "super dealloc" 
[super dealloc]; 
} 
@end 

而我得到的錯誤看起來像這樣。

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '+[NSInvocation invocationWithMethodSignature:]: 
method signature argument cannot be nil' 

任何想法?

回答

0

錯誤指出由於對未知方法簽名的錯誤調用而發生此錯誤。如果你提供了菜單創建使用的功能,它是否仍然崩潰?

第1步:確保棒球按鈕和牛頓按鈕指向右側選擇器,而不僅僅是不存在的「startArcher:」。

CCMenuItem *Baseballbutton = [CCMenuItemImage 
          itemFromNormalImage:@"Baseballnotpressed.png" 
          selectedImage:@"Baseballpressed.png" 
          target:self 
          selector:@selector(startBaseball:)]; // CHANGED HERE 
//Baseballbutton.position = ccp(350, 75); 
CCMenuItem *Newtonbutton = [CCMenuItemImage 
           itemFromNormalImage:@"Newtonnotpressed.png" 
           selectedImage:@"Newtonpressed.png" 
           target:self 
           selector:@selector(startNewton:)]; // CHANGED HERE 

STEP 2:取消功能,所以你其實有有效的選擇

- (void) startBanker: (id) sender 
{ 
    [[CCDirector sharedDirector] replaceScene:[BankerInfoLayer scene]]; 
} 
- (void) startBaby: (id) sender 
{ 
    [[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Soldier scene]]; 
} 
- (void) startMommaduck: (id) sender 
{ 
    [[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Mage scene]]; 
} 
- (void) startBaseball: (id) sender 
{ 
    [[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Archer scene]]; 
} 
- (void) startNewton: (id) sender 
{ 
    [[CCDirector sharedDirector] replaceScene:[Backgroundinfo_Archer scene]]; 
} 
+0

我固定它的startArcher是從一個不同的遊戲,我正在發展,我沒有改變,當我複製並粘貼。 :/ – tyler53 2012-07-20 18:43:05

相關問題