1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-28 07:19:09 +02:00
MLEM/MLEM/Formatting/TextAnimation.cs
2019-09-06 15:49:59 +02:00

30 lines
1.7 KiB
C#

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
namespace MLEM.Formatting {
public static class TextAnimation {
public static float WobbleModifier = 5;
public static float WobbleHeightModifier = 1 / 8F;
public static float TypingSpeed = 20;
public static readonly DrawCharacter Default = (font, batch, totalText, index, effectStartIndex, charSt, position, color, scale, layerDepth, timeIntoAnimation) => {
font.DrawString(batch, charSt, position, color, 0, Vector2.Zero, scale, SpriteEffects.None, layerDepth);
};
public static readonly DrawCharacter Wobbly = (font, batch, totalText, index, effectStartIndex, charSt, position, color, scale, layerDepth, timeIntoAnimation) => {
var offset = new Vector2(0, (float) Math.Sin(index + timeIntoAnimation.TotalSeconds * WobbleModifier) * font.LineHeight * WobbleHeightModifier * scale);
font.DrawString(batch, charSt, position + offset, color, 0, Vector2.Zero, scale, SpriteEffects.None, layerDepth);
};
public static readonly DrawCharacter Typing = (font, batch, totalText, index, effectStartIndex, charSt, position, color, scale, layerDepth, timeIntoAnimation) => {
if (timeIntoAnimation.TotalSeconds * TypingSpeed > index - effectStartIndex + 1)
font.DrawString(batch, charSt, position, color, 0, Vector2.Zero, scale, SpriteEffects.None, layerDepth);
};
public delegate void DrawCharacter(IGenericFont font, SpriteBatch batch, string totalText, int index, int effectStartIndex, string charSt, Vector2 position, Color color, float scale, float layerDepth, TimeSpan timeIntoAnimation);
}
}