PongFE/PongFE/Renderers/Texture2DRenderer.cs

36 lines
973 B
C#

using Encompass;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PongFE.Components;
using PongFE.Extensions;
namespace PongFE.Renderers
{
public class Texture2DRenderer : OrderedRenderer<Texture2DComponent>
{
private readonly SpriteBatch _spriteBatch;
public Texture2DRenderer(SpriteBatch spriteBatch)
{
_spriteBatch = spriteBatch;
}
public override void Render(Entity entity, in Texture2DComponent textureComponent)
{
ref readonly var positionComponent = ref GetComponent<PositionComponent>(entity);
_spriteBatch.Draw(
textureComponent.Texture,
positionComponent.Position.Truncated().ToXNAVector(),
null,
Color.White,
0,
Vector2.Zero,
Vector2.One,
SpriteEffects.None,
0
);
}
}
}