MonoGame.Extended
MonoGame.Extended copied to clipboard
Entities Managed In Screens Draw Over Screen Transitions
If you generate an ECS world inside of a screen, drawing systems seem to always draw after screen transitions, causing entities to appear over top of the transition animation.
Minimal reproduction:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using MonoGame.Extended.ECS;
using MonoGame.Extended.ECS.Systems;
using MonoGame.Extended.Screens;
using MonoGame.Extended.Screens.Transitions;
namespace Sample;
public class SampleScreen(Game game) : GameScreen(game)
{
private World _world;
public override void Initialize()
{
_world = new WorldBuilder().AddSystem(new SampleSystem(new SpriteBatch(GraphicsDevice))).Build();
Game.Components.Add(_world);
base.Initialize();
}
public override void Update(GameTime gameTime) { }
public override void Draw(GameTime gameTime) { }
}
public class SampleSystem(SpriteBatch spriteBatch) : DrawSystem
{
private readonly SpriteBatch _spriteBatch = spriteBatch;
public override void Draw(GameTime gameTime)
{
_spriteBatch.Begin();
_spriteBatch.FillRectangle(new RectangleF(100, 100, 100, 100), Color.Orange);
_spriteBatch.End();
}
}
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private ScreenManager _screenManager;
public Game1() { _graphics = new GraphicsDeviceManager(this); }
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
_screenManager = new ScreenManager();
Components.Add(_screenManager);
_screenManager.LoadScreen(new SampleScreen(this), new ExpandTransition(GraphicsDevice, Color.Black, 5f));
}
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime);}
}