这段代码有什么问题? [英] Whats wrong with this code?

查看:71
本文介绍了这段代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if (bool232 == true)
            {
                if (gameTime.TotalGameTime.TotalSeconds >= 3)
                {
                    this.Exit();
                }
            }
            else
            {
            }





出于某种原因,当布尔值变为true而不是等待3秒时,此代码会让我的游戏立即退出

任何想法为什么?



For some reason this code is making my game exit immediately when the boolean becomes true instead of waiting 3 seconds
any idea why?

推荐答案

好的,你编辑了这个问题让它变得如此微不一样,但是这里发生了什么...



Ok, you edited the question to make it ever so slightly different, but here is what is going on...

if (bool232 == true)





如果是真的,它将在if ...内开始执行...下一步是





When that is true, it will start executing inside the if... next is

if (gameTime.TotalGameTime.TotalSeconds >= 3)





这里,如果 TotalGameTime 结束了3秒,它将执行下一行,退出y我们的比赛。这条线不是延迟,它只是检查你是否已经玩了超过3秒。如果你想延迟,你必须这样睡觉,比如:





Here, if the TotalGameTime is over 3 seconds, it will execute the next line, which exits your game. This line is not a delay, it just check to see if you have been playing for more than 3 seconds. If you want to delay, you have to so some kind of sleep, like:

System.Threading.Thread.Sleep(3000);
this.Exit();


显然.TotalSeconds大于或者等于3。



我的第一个检查是查看TotalSeconds是否返回毫秒,1000毫秒远大于3.或者TotalSeconds是否正确初始化?
Well obviously the .TotalSeconds is greater than or equal to 3 at that point.

My first check would be to see if TotalSeconds is returning milliseconds a 1000 milliseconds is much greater than 3. Or is the TotalSeconds being initialized correctly?


请不要重新发布:



为什么这段代码不起作用? [ ^ ]
Please don't repost:

why doesnt this code work?[^]


这篇关于这段代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆