【问题标题】:How to make RPG animated text in C#? [closed]如何在 C# 中制作 RPG 动画文本? [关闭]
【发布时间】:2016-10-20 10:05:17
【问题描述】:

所以我在 C# 控制台应用程序中制作游戏,我很好奇如何制作类似 RPG 中的动画文本样式之类的东西。任何帮助将不胜感激。

【问题讨论】:

标签: c# console


【解决方案1】:

这个函数应该可以解决问题:

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);
    }
}

【讨论】:

  • 显示错误:错误 CS5001。
  • 显示错误;错误 CS5001
  • 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&lt;T&gt;(T message, int delay = 100) { foreach (char character in message.ToString()) { Console.Write(character); System.Threading.Thread.Sleep(delay); } } } }
  • 我将您的代码复制到 VS 中,它可以正常工作。尝试重建您的解决方案或将其复制到新项目中。
猜你喜欢
  • 2022-10-08
  • 2021-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-16
  • 1970-01-01
  • 2021-07-20
相关资源
最近更新 更多