【发布时间】:2016-10-20 10:05:17
【问题描述】:
所以我在 C# 控制台应用程序中制作游戏,我很好奇如何制作类似 RPG 中的动画文本样式之类的东西。任何帮助将不胜感激。
【问题讨论】:
-
这不是我想要的。
-
更具体。我们只能猜测您所说的“像您在 RPG 中看到的动画文本样式”是什么意思。
所以我在 C# 控制台应用程序中制作游戏,我很好奇如何制作类似 RPG 中的动画文本样式之类的东西。任何帮助将不胜感激。
【问题讨论】:
这个函数应该可以解决问题:
static void SimulateTyping(string message, int delay = 100) { //'delay' is optional when calling the function
foreach (char character in message) //take every character from your string seperately
{
Console.Write(character); //print one character
System.Threading.Thread.Sleep(delay); //wait for a small amount of time
}
}
你也可以让它通用,不仅仅是写字符串(int、float等):
static void SimulateTyping<T>(T message, int delay = 100) {
foreach (char character in message.ToString())
{
Console.Write(character);
System.Threading.Thread.Sleep(delay);
}
}
【讨论】:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_sharp_Testing { class Program { static void Main(string[] args) { } static void SimulateTyping<T>(T message, int delay = 100) { foreach (char character in message.ToString()) { Console.Write(character); System.Threading.Thread.Sleep(delay); } } } }