32 lines
958 B
C#
32 lines
958 B
C#
using Microsoft.Xna.Framework.Content;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using Syntriax.Engine.Core;
|
|
using Syntriax.Engine.Integration.MonoGame;
|
|
|
|
namespace Pong.Behaviours;
|
|
|
|
public class Label : Behaviour2D, IDrawableSprite, ILoadContent
|
|
{
|
|
public SpriteFont? Font { get; set; } = null;
|
|
public ColorRGBA Color { get; set; } = new ColorRGBA(255, 255, 255, 255);
|
|
public int Size { get; set; } = 16;
|
|
public string Text { get; set; } = string.Empty;
|
|
|
|
public void Draw(ISpriteBatch spriteBatch)
|
|
{
|
|
if (Font is null)
|
|
return;
|
|
|
|
spriteBatch.DrawString(Font, Text, Transform.Position, Color.ToPreMultipliedColor(), Transform.Rotation, Vector2D.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f);
|
|
}
|
|
|
|
public void LoadContent(ContentManager content)
|
|
{
|
|
Font ??= content.Load<SpriteFont>("UbuntuMono");
|
|
}
|
|
|
|
public Label() { }
|
|
public Label(SpriteFont font) => Font = font;
|
|
}
|