fix: SpriteBatcher not drawing correctly
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
using Engine.Core;
|
using Engine.Core;
|
||||||
|
|
||||||
namespace Engine.Integration.MonoGame;
|
namespace Engine.Integration.MonoGame;
|
||||||
@@ -12,6 +14,7 @@ public class SpriteBatcher : Behaviour, IFirstFrameUpdate, IDraw
|
|||||||
private ISpriteBatch spriteBatch = null!;
|
private ISpriteBatch spriteBatch = null!;
|
||||||
private MonoGameCamera2D camera2D = null!;
|
private MonoGameCamera2D camera2D = null!;
|
||||||
|
|
||||||
|
private readonly RasterizerState rasterizerState = new() { CullMode = CullMode.CullClockwiseFace };
|
||||||
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableSprite> drawableSprites = new(GetPriority(), SortByPriority());
|
private readonly ActiveBehaviourCollectorOrdered<int, IDrawableSprite> drawableSprites = new(GetPriority(), SortByPriority());
|
||||||
|
|
||||||
public void FirstActiveFrame()
|
public void FirstActiveFrame()
|
||||||
@@ -26,7 +29,13 @@ public class SpriteBatcher : Behaviour, IFirstFrameUpdate, IDraw
|
|||||||
|
|
||||||
public void Draw()
|
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++)
|
for (int i = 0; i < drawableSprites.Count; i++)
|
||||||
drawableSprites[i].Draw(spriteBatch);
|
drawableSprites[i].Draw(spriteBatch);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|||||||
Reference in New Issue
Block a user