feat: ISpriteBatch added for MonoGame integration

This commit is contained in:
2025-06-03 23:38:25 +03:00
parent 9edf3b0aa6
commit 24d1a1d764
5 changed files with 114 additions and 7 deletions

View File

@@ -1,7 +1,5 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Syntriax.Engine.Core;
namespace Syntriax.Engine.Integration.MonoGame;
@@ -9,8 +7,10 @@ namespace Syntriax.Engine.Integration.MonoGame;
public class SpriteBatcher : BehaviourBase, IFirstFrameUpdate, IDraw
{
private static Comparer<IBehaviour> SortByPriority() => Comparer<IBehaviour>.Create((x, y) => y.Priority.CompareTo(x.Priority));
private SpriteBatch spriteBatch = null!;
private ISpriteBatch spriteBatch = null!;
private MonoGameCamera2DBehaviour camera2D = null!;
private readonly ActiveBehaviourCollectorSorted<IDrawableSprite> drawableSprites = new() { SortBy = SortByPriority() };
public void FirstActiveFrame()
@@ -18,7 +18,7 @@ public class SpriteBatcher : BehaviourBase, IFirstFrameUpdate, IDraw
MonoGameWindowContainer windowContainer = Universe.FindRequiredBehaviour<MonoGameWindowContainer>();
camera2D = Universe.FindRequiredBehaviour<MonoGameCamera2DBehaviour>();
spriteBatch = new(windowContainer.Window.GraphicsDevice);
spriteBatch = new SpriteBatchWrapper(windowContainer.Window.GraphicsDevice);
drawableSprites.Unassign();
drawableSprites.Assign(Universe);
}