我想知道哪種方法是製作遊戲暫停菜單的最簡單或「最聰明」的方式?如何爲iPhone遊戲製作一個暫停菜單?
我沒有太多的經驗來創建遊戲暫停菜單,所以我嘗試了2種方法,我自己想出了。本文下面都有代碼或代碼。
我嘗試的第一種方法是在遊戲的頂部放置一個黑色的幾乎透明的過濾器,我暫停了。我成功地暫停了一切,除了在我的uiimages上過濾器下面的觸摸。我認爲在當前版面上放置一個新的uiimage會禁用它下面的uiimages。我試着用touchenabled = NO,但仍然沒有。
-(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];
}
我試過的第二種方法是要回去(切換視圖)主菜單上的選項,使用來自那裏的設置,而不用,但我wasn't能夠恢復回哪裏我暫停了比賽。相反,遊戲從一開始就重新開始。
-(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.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];
}
有如何使一個神暫停菜單或者只是重做兩個中的一個,我已經嘗試了第三種選擇?
這種方法會禁用觸摸嗎? :) – iphonedevonthemake 2011-04-13 07:04:18
在觸動你的同時也可以查看類似的概念。如果您正在做任何觸摸操作,而不是檢查相同的條件,並且忽略遊戲暫停。 – 2011-04-13 07:09:51
你的意思是在觸摸方法? – iphonedevonthemake 2011-04-13 07:12:43