2012-07-21 75 views
0

我有這個菜單項,我想連接到我的xib文件,並想知道如何做到這一點?我認爲這可能像普通的Xcode,但它不像我認爲的那樣。真的很感激,如果你幫我。將菜單項連接到xib文件cocos2d?

CCMenuItemImage *gamecenter = [CCMenuItemImage 
           itemFromNormalImage:@"gamecenter.png" 
           selectedImage:@"gamecenter.png" 
           target:self 
           selector:@selector(gamecenter:)]; 

    option1.position =ccp(50,-150); 

    CCMenu *menu6 = [CCMenu menuWithItems: option2, nil]; 
    [menuLayer addChild: menu6];   

    - (void) option2: (id) sender 
{ 
    [[CCDirector sharedDirector] replaceScene:[GameCenterViewController scene]]; 


} 

我知道你可能不使用GameCenterViewController(xib文件)來替換場景。但只要把它展現出來就是我想要做的。

回答

0

我假設GameCenterViewController是一個Cocos2d CCLayer。如果不是,請告訴我,我將編輯答案...

- (id)init 
{ 
    CCMenuItemImage *gameCenterMenuItem = [CCMenuItemImage 
            itemFromNormalImage:@"gamecenter.png" 
            selectedImage:@"gamecenter.png" 
            target:self 
            selector:@selector(gamecenter:)]; 

    CCMenu *menu = [CCMenu menuWithItems: gameCenterMenuItem, nil]; 

    [menuLayer addChild: menu]; 
} 

- (void)gamecenter: (CCMenuItem *)menuItem 
{ 
    [[CCDirector sharedDirector] replaceScene:[GameCenterViewController scene]]; 
}