开发者

how to make a pause menu for iphone game?

I was wondering which method is the easiest or "smartest" way of making a pause menu for games?

I don´t have that much experience with creating game pause menus so I´ve tried 2 methods that I came up with by my own. Both or in code beneath this text.

The first method I tried was to put a black almost transparent filter on top of the game, that I paused. I was successful with pausing everything except the touches made underneath the filter on my uiimages. I thought that putting a new uiimage on top of the current one would disable the touches made on the uiimages underneath it. I tried as well with touchenabled = NO but still nothing.

-(IBAction)pause{

NSLog(@"pause");

[countdowntimer invalidate];

[self.rubin1 stopAnimating];
[self.rubin2 stopAnimating];  
[self.rubin3 stopAnimating];

Pause.enabled = NO;
music1.enabled = NO;
music2.enabled = NO;
sfx1.enabled = NO;
sfx2.enabled = NO;

//PauseMenu background
UIImage *image1 = [UIImage imageNamed: @"filter2.png"];
pausefilter = [[[UIImageView alloc] initWithImage:image1] autorelease];
CGRect newFrame1 = pausefilter.frame; 
newFrame1 = CGRectMake(0,0, image1.size.width, image1.size.height);
pausefilter.frame = newFrame1; 

[self.view addSubview:pausefilter];

[image1 release];

//Resume to Game
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(90, 146, 80, 18);
[button1 setImage:[UIImage imageNamed:@"RESUME.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(resume) forControlEvents:UIControlEventTouchUpInside];
[ self.view addSubview: button1 ];

//End Game
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(260, 140, 180, 30);
[button2 setImage:[UIImage imageNamed:@"EndGame.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(end) forControlEvents:UIControlEventTouchUpInside];
[ self.view addSubview: button2 ];

[sharedSoundManager pausePlayingMusic];

}

The second method I tried was to go back (switch view) to the options on the main menu to use the settings from there instead but I wasn´t able to resume back to where I paused the game. Instead the game restarted from the beginning.

-(IBAction)pause{

NSLog(@"pause");

[countdowntimer invalidate];

[self.rubin1 stopAnimating];
[self.rubin2 stopAnimating];  
[self.rubin3 stopAnimating];

Pause.enabled = NO;
music1.enabled = NO;
music2.enabled = NO;
sfx1.enabled = NO;
sfx2.enabled = NO;

menureturn = [[MainMenu alloc] initWithNibName:@"MainMenu" bundle: nil];
menureturn.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:menureturn animated: YES];

self.menureturn.Start.hidden = YES;
self.menureturn.option.hidden = YES;
self.menureturn.OptionsHeadtitle.hidden = NO;
self.menureturn.HowToPlayHeadtitle.hidden = YES;
self.menureturn.howtoplay.hidden = YES;
self.menureturn.filter.hidden = NO;
self.menureturn.music1.hidden = NO;
self.menureturn.music2.hidden = YES;
self.menureturn开发者_如何学JAVA.SFXimage.hidden = NO; 
self.menureturn.Musicimage.hidden = NO; 
self.menureturn.sfx1.hidden = NO;
self.menureturn.sfx2.hidden = YES;
self.menureturn.credits.hidden = YES;
self.menureturn.back.hidden = YES;
self.menureturn.creditsinfo.hidden = YES;
self.menureturn.resume.hidden = NO;
self.menureturn.endgame.hidden = NO;

[sharedSoundManager pausePlayingMusic];

}

Is there a third option of how to make a god pause menu or just redo one of the two I already tried?


You can have a BOOL variable like

BOOL isGamePaused

Now when you are playing game i.e running not paused assign

isGamePaused = NO;

While you pause

isGamePaused = YES;

Now while playing animation or something like that you can use condition like

if(!isGamePaused) { ProceedAnimation;}

Hope this helps


The best thing to disable any event is to create a new element in your pause menu which will be the first responder and catches all events. So nothing can arrive to your game's interface ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜