SpriteComponent.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include "Component.h"
  10. #include "SDL/SDL.h"
  11. class SpriteComponent : public Component
  12. {
  13. public:
  14. // (Lower draw order corresponds with further back)
  15. SpriteComponent(class Actor* owner, int drawOrder = 100);
  16. ~SpriteComponent();
  17. virtual void Draw(class Shader* shader);
  18. virtual void SetTexture(class Texture* texture);
  19. int GetDrawOrder() const { return mDrawOrder; }
  20. int GetTexHeight() const { return mTexHeight; }
  21. int GetTexWidth() const { return mTexWidth; }
  22. void SetVisible(bool visible) { mVisible = visible; }
  23. bool GetVisible() const { return mVisible; }
  24. TypeID GetType() const override { return TSpriteComponent; }
  25. void LoadProperties(const rapidjson::Value& inObj) override;
  26. void SaveProperties(rapidjson::Document::AllocatorType& alloc,
  27. rapidjson::Value& inObj) const override;
  28. protected:
  29. class Texture* mTexture;
  30. int mDrawOrder;
  31. int mTexWidth;
  32. int mTexHeight;
  33. bool mVisible;
  34. };