mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 12:06:37 +00:00
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using Demo.Platformer.Entities.Components;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace Demo.Platformer.Entities.Systems
|
|
{
|
|
public class SpriteBatchComponentSystem : DrawableComponentSystem
|
|
{
|
|
public SpriteBatchComponentSystem(GraphicsDevice graphicsDevice)
|
|
{
|
|
_spriteBatch = new SpriteBatch(graphicsDevice);
|
|
}
|
|
|
|
private readonly SpriteBatch _spriteBatch;
|
|
|
|
public override void Draw(GameTime gameTime)
|
|
{
|
|
var spriteComponents = GetComponents<SpriteComponent>();
|
|
|
|
_spriteBatch.Begin();
|
|
|
|
foreach (var sprite in spriteComponents)
|
|
{
|
|
if (sprite.IsVisible)
|
|
{
|
|
var texture = sprite.TextureRegion.Texture;
|
|
var sourceRectangle = sprite.TextureRegion.Bounds;
|
|
|
|
_spriteBatch.Draw(texture, sprite.Position, sourceRectangle, sprite.Color * sprite.Alpha, sprite.Rotation, sprite.Origin,
|
|
sprite.Scale, sprite.Effect, sprite.Depth);
|
|
}
|
|
}
|
|
_spriteBatch.End();
|
|
}
|
|
}
|
|
} |