little explosions and fixed more bugs in the ecs

This commit is contained in:
Dylan Wilson
2018-07-31 21:52:13 +10:00
parent defeac7b97
commit ccf03f18ed
8 changed files with 58 additions and 19 deletions
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended;
using MonoGame.Extended.Animations;
using MonoGame.Extended.Entities;
using MonoGame.Extended.Entities.Systems;
using MonoGame.Extended.Sprites;
@@ -13,9 +14,10 @@ namespace JamGame.Systems
private ComponentMapper<Transform2> _transformMapper;
private ComponentMapper<Sprite> _spriteMapper;
private ComponentMapper<AnimatedSprite> _animatedSpriteMapper;
public SpriteRenderingSystem(GraphicsDevice graphicsDevice, Texture2D texture)
: base(Aspect.All(typeof(Transform2), typeof(Sprite)))
: base(Aspect.All(typeof(Transform2)).One(typeof(Sprite), typeof(AnimatedSprite)))
{
_spriteBatch = new SpriteBatch(graphicsDevice);
}
@@ -24,6 +26,7 @@ namespace JamGame.Systems
{
_transformMapper = mapperService.GetMapper<Transform2>();
_spriteMapper = mapperService.GetMapper<Sprite>();
_animatedSpriteMapper = mapperService.GetMapper<AnimatedSprite>();
}
public override void Draw(GameTime gameTime)
@@ -33,9 +36,12 @@ namespace JamGame.Systems
foreach (var entity in ActiveEntities)
{
var transform = _transformMapper.Get(entity);
var animatedSprite = _animatedSpriteMapper.Get(entity);
var sprite = _spriteMapper.Get(entity);
_spriteBatch.Draw(sprite, transform);
animatedSprite?.Update(gameTime);
_spriteBatch.Draw(sprite ?? animatedSprite, transform);
}
_spriteBatch.End();