using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MonoGame.Extended; using MonoGame.Extended.Entities; using MonoGame.Extended.Entities.Systems; namespace Sandbox.Systems { public class RenderSystem : EntityDrawSystem { private readonly GraphicsDevice _graphicsDevice; private readonly SpriteBatch _spriteBatch; private ComponentMapper _transformMapper; public RenderSystem(GraphicsDevice graphicsDevice) : base(Aspect.All(typeof(Transform2))) { _graphicsDevice = graphicsDevice; _spriteBatch = new SpriteBatch(graphicsDevice); } public override void Initialize(IComponentMapperService mapperService) { _transformMapper = mapperService.GetMapper(); } public override void Draw(GameTime gameTime) { _graphicsDevice.Clear(Color.Black); _spriteBatch.Begin(samplerState: SamplerState.PointClamp); foreach (var entity in ActiveEntities) { var transform = _transformMapper.Get(entity); _spriteBatch.FillRectangle(transform.Position, new Size2(3, 3), Color.LightBlue); } _spriteBatch.End(); } } }