I'm working on my game but I am stuck at this easy step and hoping that you guys will shine your light on me and guide me through.
I have two classes with xibs: one of them is MainMenu, another is MainGame,
In MainMenu, I have action button that switches into the开发者_Go百科 MainGame xib.
My request is, I want to make another action in the MainMenu that will take me to MainGame but instead of the current game mode I have, I want to make a let's say "hard" mode which will shorten the time.
Here's my code:
timeRemaining2 = 10.0f;
So, what exactly I want to know how to do is, how can I setup an action button in the MainMenu where if click it, it will take me to the MainGame mode where I can I setup:
if(hardMode) {
timeRemaining2 = 5.0f;
}
I'm not sure how you're creating and presenting your MainGame view controller, so I'll leave that bit up to you. But here is a basic explanation of how to set up an instance variable to set and hold the timeRemaining value. In MainGame set up an instance variable. MainGame.h
@property float timeRemaining2;
Remember to synthesize this (to get setters and getters for free) in your MainGame.m
@sythesize timeRemaining2;
In your MainMenu, set up two IBActions, and connect each to its relevant button in Interface Builder MainMenu.xib. Then in your MainMenu.h
- (IBAction)easyTapped;
- (IBAction)hardTapped;
In your MainMenu.m, define what happens when those messages are called:
- (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
}
精彩评论