From Gruff Owl, 7 Months ago, written in Plain Text.
This paste will croak in 3 Months.
Embed
  1. #include "Systems/RenderSystem.hpp"
  2. #include "Components/GraphicsComponent.hpp"
  3. #include "Components/PositionComponent.hpp"
  4. #include <SFML/Graphics.hpp>
  5.  
  6. void RenderSystem::setRenderWindow(sf::RenderWindow* w) {
  7.     this->window = w;
  8. }
  9.  
  10. int RenderSystem::drawEntity(Entity* e) {
  11.  
  12.     GraphicsComponent* gc = e->get<GraphicsComponent>();
  13.     PositionComponent* pc = e->get<PositionComponent>();
  14.     if (gc != nullptr && pc != nullptr) {
  15.         sf::Sprite sprite = *gc->getSprite();
  16.         sprite.setTexture(*gc->getTextureRef());
  17.         sprite.setScale(gc->getScale());
  18.         sprite.setTextureRect(gc->getRect());
  19.         sprite.setPosition(pc->getX(), pc->getY());
  20.         this->window->draw(sprite);
  21.         return 1;
  22.     }
  23.     else {
  24.         printf("Entity is not drawable: Missing Graphics or Position component\n");
  25.         return -1;
  26.     }
  27.  
  28. }