Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. public static bool Speaking;
  2.         const int TypeSpeed = 50;
  3.         private static readonly char[] SlowChars = new char[] { '!', '?', ',', '.' };
  4.         public static void AnimatedText(string Text, bool speech = false, bool Centering = false)
  5.         {
  6.             Speaking = true;
  7.             if (Centering)
  8.                 Console.CursorLeft = (Console.BufferWidth - Text.Length) / 2;
  9.             ThreadPool.QueueUserWorkItem(delegate
  10.             {
  11.                 for (int i = 0; i < Text.Length; i++)
  12.                 {
  13.                     if (Speaking)
  14.                     {
  15.                         if (SlowChars.Contains(Text[i]) && speech)
  16.                         {
  17.                             Console.Write(Text[i]);
  18.                             Thread.Sleep(TypeSpeed * 10);
  19.                         }
  20.                         else
  21.                         {
  22.                             Console.Write(Text[i]);
  23.                             Thread.Sleep(TypeSpeed);
  24.                         }
  25.                     }
  26.                 }
  27.                 Console.WriteLine();
  28.                 Speaking = false;
  29.             });
  30.             Console.ReadKey(true);
  31.             Speaking = false;
  32.             Console.Clear();
  33.             if (Centering)
  34.                 Console.CursorLeft = (Console.BufferWidth - Text.Length) / 2;
  35.             Console.WriteLine(Text);
  36.             Console.ReadKey(true);
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement