refactor: moved font loading to label
This commit is contained in:
parent
44a366f475
commit
863c3a8d7a
2
Engine
2
Engine
@ -1 +1 @@
|
||||
Subproject commit ad365dc7225df5df0d8be0729f6c62490c845f77
|
||||
Subproject commit 37aca44e45923511500ee1e6a8f39a30810b7f63
|
@ -1,4 +1,4 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
@ -6,9 +6,10 @@ using Syntriax.Engine.Integration.MonoGame;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class Label : Behaviour2D, IDrawableSprite
|
||||
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;
|
||||
|
||||
@ -17,7 +18,12 @@ public class Label : Behaviour2D, IDrawableSprite
|
||||
if (Font is null)
|
||||
return;
|
||||
|
||||
spriteBatch.DrawString(Font, Text, Transform.Position, Color.White, Transform.Rotation, Vector2D.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f);
|
||||
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() { }
|
||||
|
@ -1,12 +1,8 @@
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
using Syntriax.Engine.Core;
|
||||
using Syntriax.Engine.Integration.MonoGame;
|
||||
|
||||
namespace Pong.Behaviours;
|
||||
|
||||
public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate, ILoadContent
|
||||
public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate
|
||||
{
|
||||
public readonly bool IsLeft = IsLeft;
|
||||
|
||||
@ -22,11 +18,6 @@ public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate, ILoadContent
|
||||
UpdateScores(pongManager);
|
||||
}
|
||||
|
||||
public void LoadContent(ContentManager content)
|
||||
{
|
||||
Font = content.Load<SpriteFont>("UbuntuMono");
|
||||
}
|
||||
|
||||
private void UpdateScores(PongManager pongManager)
|
||||
{
|
||||
if (IsLeft)
|
||||
|
Loading…
x
Reference in New Issue
Block a user