我正在制作一个复古风格的游戏C# .NET-Framework,对于对话,我使用了一个 for 语句,它会一个字母一个字母地打印我的文本(就像打字机效果):
我正在处理不同的场景,我有一个跳过按钮(右下角)可以跳过当前对话并传递到下一个场景。当显示所有文本时,我的打字机效果会自动停止,但是当我单击跳过按钮时,它会自动跳到下一个场景。
我希望在打字机仍处于活动状态时,如果我单击跳过按钮,它首先显示所有文本,而不是跳到下一个场景。
这样它只会在显示所有文本时(自动或手动)跳到下一个场景。
这是我用于打字机方法(+ 变量)的(工作代码):
public string FullTextBottom;
public string CurrentTextBottom = "";
public bool IsActive;
public async void TypeWriterEffectBottom()
{
if(this.BackgroundImage != null) // only runs on backgrounds that arent black
{
for(i=0; i < FullTextBottom.Length + 1; i++)
{
CurrentTextBottom = FullTextBottom.Substring(0, i); // updating current string with one extra letter
LblTextBottom.Text = CurrentTextBottom; // "temporarily place string in text box"
await Task.Delay(30); // …Run Code Online (Sandbox Code Playgroud)