2009-11-04 24 views
1

我正在開發一個遊戲,其中所有的設置頁面,得分頁面,幫助頁面都在筆尖形成,並且遊戲採用cocos2d場景格式(Gamescene.h和m文件)。所以我需要從筆尖按下「開始遊戲」按鈕時從一個筆尖文件調用遊戲場景。當遊戲結束時,我需要從cocos場景中調用分數.nib。但我不知道如何做到這一點....COCOS2D:如何從椰樹菜單中調用nib文件,反之亦然?

任何人都可以給我一個簡單的解決方案嗎?提前致謝!

問候,苯並咪唑。

回答

3

在應用我創建我通常cocos2d的導演附加到一個視圖即

[[Director shareddirector] attachInView:myView]; 

這意味着,我可以覆蓋從在它前面的碎粒加載其它視圖。例如。我可以做類似的事情。 。 。

在YourAppDelegate.h

GameViewController *gameViewController; 
ScoresViewcontroller *scoresViewController; 

.... 

@property (nonatomic, retain) GameViewController *gameViewController; 
@property (nonatomic, retain) ScoresViewController *scoresViewController; 

和YourAppDelegate.m內的applicationDidFinishLaunching:

// Create the cocos2d view 
gameViewController = [[GameViewController alloc] init]; 
[window addSubview:gameViewController.view]; 

// Create the high scores view and controller 
scoresViewController = [[ScoresViewController alloc] initwithNibName:@"scoresNib" 
                   bundle:nil]; 
[window addSubview:scoresViewController.view]; 

最後,GameViewController裏面你會

- (void) loadView { 
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)]; 

    [[Director sharedDirector] attachInView:self.view]; 

    // Now do your cocos2d scene stuff to start everything off e.g. create a scene 
    // and call runWithScene: on the sharedDirector 
} 

這裏,cocos2d的代碼在後臺運行,分數視圖覆蓋在前面(或隱藏,直到你需要它等)。

然後,當你的遊戲需要做一些事來的高分,在GameViewController可以直接從應用程序的委託獲得HighScoresViewController即

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate]; 
appDelegate.scoresViewController.view.hidden = NO; 

山姆

PS的答案this question也可能是對你有用:)

+0

嗨, Thanks.This適用於我....但它是唯一的想法...? – Rony 2010-08-09 05:06:42

相關問題