Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用C暂停游戏#_C# - Fatal编程技术网

C# 如何使用C暂停游戏#

C# 如何使用C暂停游戏#,c#,C#,如何使用C#暂停游戏?我想知道它的功能部分。我试图将while-true循环与布尔变量结合起来。当布尔值变为false时,它将在while循环中导致continue语句。以我目前的知识,我只能在游戏中的某些点上实现连续陈述 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WhileLoop {

如何使用C#暂停游戏?我想知道它的功能部分。我试图将while-true循环与布尔变量结合起来。当布尔值变为false时,它将在while循环中导致continue语句。以我目前的知识,我只能在游戏中的某些点上实现连续陈述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WhileLoop
{
    class Program
    {
        static void Main(string[] args)
        {
            bool play = true;

            while (true)
            {
                play = true;

                if (play)
                {
                    Console.WriteLine("Do something1");

                    play = false;

                    if (!play)
                    {
                        continue;
                    }

                    Console.WriteLine("Do something2");
                }
            }
            Console.WriteLine("Do something3");
        }
    }
}

既然你提到了游戏,我想它和游戏有关吧?通常情况下,奥运会有一个时间尺度。1.0是实时的。
然后在每个帧之间有一个deltaTime。任何依赖于时间的东西都使用这个因素<代码>变量移动=方向*增量时间。如果暂停游戏,将时间刻度设置为0,则可能需要使用状态机构建游戏。使用此结构,您可以在游戏中设置当前状态(如菜单、游戏、暂停、退出),并相应地运行代码。重要的是不要使用
Thread.sleep
或类似的命令,因为程序不会响应这些命令

关于这些力学的有用教程随处可见,如下所示:

我通常建议您从中查看SDL教程


祝你好运

定义暂停时预期会发生什么,以及应该如何暂停,用户交互在哪里?
继续
可能听起来像“取消暂停”,但它与此无关-它只是立即开始下一次迭代
,而
块更详细地描述你想要实现的目标。更多关于游戏本身的细节,以及它将如何与用户交互。这实际上与用户交互和游戏无关。我只是好奇,好像有一种机制,当布尔播放变为false时,会在代码中的任何特定点导致while true循环继续。