2011-09-16 23 views
0

我正在對我的遊戲進行研究,但我被困在這個簡單的步驟中,希望你們能夠將你的光芒照亮我並引導我度過。通過另一個視圖傳遞行動

我有兩個類與xibs:其中之一是MainMenu的,另一個是MainGame,

在MainMenu的,我有動作按鈕切換到MainGame XIB。

我的要求是,我想在MainMenu中做出另一個動作,將我帶到MainGame,但不是我現有的遊戲模式,我想讓我們說一下「hard」模式,這將縮短時間。

這裏是我的代碼:

timeRemaining2 = 10.0f; 

那麼,究竟我想知道如何做的是,我怎麼能安裝在MainMenu的一個操作按鈕,其中,如果點擊它,它會帶我去MainGame模式在那裏我可以我設置:

if(hardMode) { 
timeRemaining2 = 5.0f; 
} 

回答

0

我不知道你是如何製作與呈現MainGame視圖控制器,所以我會離開,有點給你。但是,下面是如何設置實例變量來設置和保存timeRemaining值的基本說明。 在MainGame中設置一個實例變量。 MainGame.h

@property float timeRemaining2; 

記住合成這種在MainGame.m(獲得setter和免費干將)

@sythesize timeRemaining2; 

在你的MainMenu,設置了兩個IBActions,每個連接到其相關在Interface Builder MainMenu.xib中的按鈕。然後在你的MainMenu.h

- (IBAction)easyTapped; 
- (IBAction)hardTapped; 

在你MainMenu.m,定義當這些消息被稱作會發生什麼:

- (IBAction)easyTapped { 
    //instantiate your mainGame view controller, or retrieve it's pointer from self. iVars or however you're doing it. 

    mainGame.timeRemaining2 = 10.0f; //sets the difficulty instance variable 
    //present the mainGame view 
} 

- (IBAction)hardTapped { 
    //instantiate your mainGame view controller, or retrieve it's pointer from self. iVars 

    mainGame.timeRemaining2 = 5.0f; //sets the difficulty instance variable 
    //present the mainGame view 
} 
相關問題