From 1400ade977e13e3b535d3c2fddb6e15de3c9b5a5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 8 Feb 2018 13:43:10 -0500 Subject: Moved sprite rendering into AnimatingSystem Refactored how systems work slightly. Now, rendering can be done by a number of systems working together. Since the AnimatingSystem handles the animation of sprites, it should also handle the rendering of them. Because of this, the RenderingSystem has been removed. --- src/systems/animating.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/systems/animating.cpp') diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp index fcbfca5..91fe925 100644 --- a/src/systems/animating.cpp +++ b/src/systems/animating.cpp @@ -1,6 +1,7 @@ #include "animating.h" #include "game.h" #include "components/animatable.h" +#include "components/transformable.h" void AnimatingSystem::tick(double) { @@ -28,6 +29,35 @@ void AnimatingSystem::tick(double) } } +void AnimatingSystem::render(Texture& texture) +{ + std::set spriteEntities = + game_.getEntityManager().getEntitiesWithComponents< + AnimatableComponent, + TransformableComponent>(); + + for (id_type entity : spriteEntities) + { + auto& sprite = game_.getEntityManager(). + getComponent(entity); + + auto& transform = game_.getEntityManager(). + getComponent(entity); + + Rectangle dstrect { + static_cast(transform.getX()), + static_cast(transform.getY()), + transform.getW(), + transform.getH()}; + + const AnimationSet& aset = sprite.getAnimationSet(); + texture.blit( + aset.getTexture(), + aset.getFrameRect(sprite.getFrame()), + dstrect); + } +} + void AnimatingSystem::startAnimation(id_type entity, std::string animation) { auto& sprite = game_.getEntityManager(). -- cgit 1.4.1