using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; using Syntriax.Engine.Core; namespace Syntriax.Engine.Integration.MonoGame; public class SpriteBatcher : BehaviourBase, IFirstFrameUpdate, IDraw { private static Comparer SortByPriority() => Comparer.Create((x, y) => y.Priority.CompareTo(x.Priority)); private SpriteBatch spriteBatch = null!; private MonoGameCamera2DBehaviour camera2D = null!; private readonly ActiveBehaviourCollectorSorted drawableSprites = new() { SortBy = SortByPriority() }; public void FirstActiveFrame() { MonoGameWindowContainer windowContainer = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour(); camera2D = BehaviourController.UniverseObject.Universe.FindRequiredBehaviour(); spriteBatch = new(windowContainer.Window.GraphicsDevice); } public void Draw() { spriteBatch.Begin(transformMatrix: camera2D.MatrixTransform); for (int i = 0; i < drawableSprites.Count; i++) drawableSprites[i].Draw(spriteBatch); spriteBatch.End(); } }