<分区>
标签 ios objective-c
我有一个游戏,当游戏结束时,游戏结束图像 (gameoverscreen.png) 可见(以前是隐藏的),并且会出现一个可以再次玩的按钮。我尝试做的是为其创建一个 IBAction,然后在该操作中重新加载 viewDidLoad。
例子:
-(IBAction)restartGame:(id)sender{
[self viewDidLoad]; //to reload the screen
gameoverscreen.hidden = YES;
replayButton.hidden = YES;
}
我以为这会重新加载屏幕,但它只出现半秒钟,然后游戏结束屏幕再次可见。我认为这与我的 NSTimer 有关,但是当 gameoverscreen.hidden = NO;
时计时器无效所以不是那样.. 为什么它不能正确地重新加载屏幕并允许用户再次播放的任何原因?
最佳答案
好吧,我本身无法回答问题,但我可以提供建议...这就是我想象的您的起始代码的样子...
-(void)viewDidLoad
{
NSTimer *t = [some timer code to start the loop and process events]
//init some other state stuff, arrays of rects etc.
}
-(IBAction)restartGame:(id)sender{
[self viewDidLoad]; //to reload the screen
gameoverscreen.hidden = YES;
replayButton.hidden = YES;
}
你的代码应该是这样的:
-(void)viewDidLoad
{
[self restartGame];
}
- (void)setUpInitalGameState
{
//init some other state stuff, arrays of rects etc.
}
- (void)start
{
NSTimer *t = [some timer code to start the loop and process events]
}
-(IBAction)restartGame:(id)sender{
[self setUpInitialGameState];
[self start];
}
关于ios - 怎么打重法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22108150/