Advertisement
RageDoc

DrawText

Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.48 KB | None | 0 0
  1. public static void DrawString(string s, Vector2 startPos, SpriteBatch spriteBatch, int maxWidth = 300)
  2.         {
  3.             Vector2 currentPosition = startPos;
  4.             char[] chars = s.ToCharArray();
  5.             int length = 0;
  6.             int currentLine = 1;
  7.             float ylock = startPos.Y;
  8.             for(int i = 0; i < s.Length; i++)
  9.             {
  10.                 if(chars[i] == wavyChar)
  11.                 {
  12.                     waving = !waving;
  13.                 }
  14.                 else if(chars[i] == jitterChar)
  15.                 {
  16.                     jittering = !jittering;
  17.                 }
  18.                 else if(chars[i] == phaseChar)
  19.                 {
  20.                     phasing = !phasing;
  21.                 }
  22.                 else if(chars[i] == screamChar)
  23.                 {
  24.                     screaming = !screaming;
  25.                 }
  26.                 else
  27.                 {
  28.                     int incr;
  29.                     if (i != 0)
  30.                         incr = MeasureChar(chars[i - 1]);
  31.                     else
  32.                         incr = 0;
  33.  
  34.                     if (waving)
  35.                     {
  36.                         //no lerp/rough
  37.                         //currentPosition += new Vector2(incr, (float)Math.Floor(Math.Cos((animationIncrement / 7) + (i / 2)) * 2.2));
  38.  
  39.                         //lerp/smooth
  40.                         currentPosition += new Vector2(incr, (float)(Math.Cos((animationIncrement / 7) + (i / 2)) * 2.2));
  41.                     }
  42.                     else if (jittering)
  43.                     {
  44.                         currentPosition += new Vector2(incr, (float)Math.Cos((animationIncrement + (i * 1.2f)) * .9f));
  45.                     }
  46.                     else if (phasing)
  47.                     {
  48.                         currentPosition += new Vector2(incr, (float)Math.Cos((animationIncrement) * 3));
  49.                     }
  50.                     else if (screaming)
  51.                     {
  52.                         currentPosition += new Vector2(incr + (float)Math.Cos((animationIncrement) * 2f), (float)Math.Cos((animationIncrement + (i / 2))));
  53.                     }
  54.                     else
  55.                     {
  56.                         currentPosition += new Vector2(incr, 0);
  57.                     }
  58.  
  59.                     length += incr;
  60.                     Vector2 dictPos = charPosition[chars[i]];
  61.                     Rectangle charSource = new Rectangle((int)dictPos.X, (int)dictPos.Y, charPositionSize, charPositionSize);
  62.  
  63.                     if (chars[i] == ' ' && i != s.Length - 1)
  64.                     {
  65.                         if (length + LengthOfNextWord(s.Substring(i)) > maxWidth)
  66.                         {
  67.                             currentLine++;
  68.                             currentPosition = startPos + new Vector2(-MeasureChar(' '), (currentLine * charPositionSize) + verticalSpacing);
  69.                             ylock = currentPosition.Y;
  70.                             length = 0;
  71.                         }
  72.                     }
  73.  
  74.                     spriteBatch.Draw
  75.                     (
  76.                         texture: mainFont,
  77.                         sourceRectangle: charSource,
  78.                         position: currentPosition,
  79.                         color: Color.White
  80.                     );
  81.                 }
  82.  
  83.                 currentPosition = new Vector2(currentPosition.X, ylock);
  84.             }
  85.  
  86.             waving = false;
  87.             jittering = false;
  88.             phasing = false;
  89.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement