0

そこで、自分が開発したゲームのメニューを作成しようとしています。私はCocos2dを使用しており、ゲームは縦向きに設定されています。私が書いたmenu.mファイルはこんな感じです。

// 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'

何か案は?

4

1 に答える 1

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

ステップ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]];
}
于 2012-07-19T00:49:30.963 に答える