ios - 怎么打重法?

标签 ios objective-c

<分区>


想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post .

已关闭 9 年前

我有一个游戏,当游戏结束时,游戏结束图像 (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/

上一篇:ios - Corona SDK transition.to 和物理体不正确

下一篇:ios - 将应用程序放到 iphone 上进行测试的步骤是什么?

相关文章:

ios - XIB 中的 UITabelViewCell 将被实例化更多次

ios - weakSelf 在 block 之前被释放

ios - 从 uiviewcontroller 引用 uiviewtablecontroller

iOS 与表情符号等消息中的文本共享图像

ios - 为什么更改 UIImageView 内容模式会影响其在 Xcode6 中的自动布局?

ios - SKTextureAtlas:不止一个图集令人困惑

objective-c - 将 NSJSONSerialization 转换为 iOS 4

ios - 月份更改时调用的 FSCalendar 函数

ios - Google map URL 方案不适用于 iOS 9

objective-c - 应用程序不释放内存,内存使用量每次都会增加一倍