fix: SpriteBatcher not drawing correctly

This commit is contained in:
2026-03-28 22:35:47 +03:00
parent 0707665481
commit fe0173b091

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Engine.Core;
namespace Engine.Integration.MonoGame;
@@ -12,6 +14,7 @@ public class SpriteBatcher : Behaviour, IFirstFrameUpdate, IDraw
private ISpriteBatch spriteBatch = null!;
private MonoGameCamera2D camera2D = null!;
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.CullClockwiseFace };
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableSprite> drawableSprites = new(GetPriority(), SortByPriority());
public void FirstActiveFrame()
@@ -26,7 +29,13 @@ public class SpriteBatcher : Behaviour, IFirstFrameUpdate, IDraw
public void Draw()
{
spriteBatch.Begin(transformMatrix: camera2D.ViewMatrix.ToXnaMatrix());
Matrix4x4 transformMatrix = Matrix4x4.Identity
.ApplyTranslation(new Vector2D(camera2D.Viewport.X, camera2D.Viewport.Y) * .5f)
.ApplyScale(new Vector3D(1f, -1f, 1f))
.ApplyMatrix(camera2D.ViewMatrix)
.Transposed;
spriteBatch.Begin(transformMatrix: transformMatrix.ToXnaMatrix(), rasterizerState: rasterizerState);
for (int i = 0; i < drawableSprites.Count; i++)
drawableSprites[i].Draw(spriteBatch);
spriteBatch.End();