我想知道哪种方法是制作游戏暂停菜单的最简单或“最智能”的方式?
我没有那么多创建游戏暂停菜单的经验,所以我尝试了自己提出的两种方法。本文下面的代码或代码。
我尝试的第一种方法是在游戏顶部放置一个黑色的几乎透明的滤镜,我暂停了。我成功地暂停了除了在我的uiimages上过滤器下面的触摸之外的所有内容。我认为在当前的uiimage之上放置一个新的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];
}
我尝试的第二种方法是返回(切换视图)到主菜单上的选项以使用那里的设置,但我无法恢复到我暂停游戏的位置。相反,游戏从一开始就重新开始。
-(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];
}
有没有第三种方法可以制作一个神暂停菜单,或者只是重做我已尝试过的两个中的一个?
答案 0 :(得分:3)
您可以拥有像
这样的BOOL变量BOOL isGamePaused
现在你正在玩游戏,即没有暂停分配
isGamePaused = NO;
暂停时
isGamePaused = YES;
现在在播放动画或类似内容时,您可以使用
之类的条件if(!isGamePaused){ProceedAnimation;}
希望这有帮助
答案 1 :(得分:0)
禁用任何事件的最佳方法是在暂停菜单中创建一个新元素,该元素将成为第一个响应者并捕获所有事件。所以没有任何东西可以到达你的游戏界面;)