Peoplemon  0.1.0
Peoplemon 3 game source documentation
Renderable.hpp
Go to the documentation of this file.
1 #ifndef CORE_COMPONENTS_RENDERABLE_HPP
2 #define CORE_COMPONENTS_RENDERABLE_HPP
3 
4 #include <BLIB/ECS/Registry.hpp>
5 #include <BLIB/Graphics/Animation2D.hpp>
6 #include <BLIB/Graphics/Slideshow.hpp>
7 #include <BLIB/Graphics/Sprite.hpp>
8 #include <BLIB/Resources.hpp>
9 #include <BLIB/Tilemap/Position.hpp>
13 
14 namespace core
15 {
16 namespace system
17 {
18 class Render;
19 }
20 
21 namespace component
22 {
28 class Renderable {
29 public:
33  Renderable();
34 
44  static Renderable& createFromSprite(bl::engine::Engine& engine, bl::ecs::Entity entity,
45  bl::rc::Scene* scene, const std::string& path);
46 
56  static Renderable& createFromMoveAnims(bl::engine::Engine& engine, bl::ecs::Entity entity,
57  bl::rc::Scene* scene, const std::string& path);
58 
68  static Renderable& createFromFastMoveAnims(bl::engine::Engine& engine, bl::ecs::Entity entity,
69  bl::rc::Scene* scene, const std::string& path);
70 
80  static Renderable& createFromAnimation(bl::engine::Engine& engine, bl::ecs::Entity entity,
81  bl::rc::Scene* scene, const std::string& path);
82 
86  float animLength() const;
87 
93  void triggerAnim(bool loop);
94 
102  void notifyMoveState(bl::tmap::Direction dir, bool moving, bool running);
103 
109  void setAngle(float angle);
110 
114  bl::com::Transform2D& getTransform() { return *transform; }
115 
121  void setHidden(bool hide);
122 
123 private:
124  enum SourceType { Walk, Run, SingleAnim, Sprite } srcType;
125  union {
128  bl::gfx::a2d::AnimationData* animSrc;
129  };
130  bl::rc::rcom::DrawableBase* drawable;
131  bl::com::Transform2D* transform;
132  bl::com::Animation2DPlayer* player;
133  bl::ecs::Entity shadow;
134  bool isMoving;
135 
136  friend class system::Render;
137 };
138 
139 } // namespace component
140 } // namespace core
141 
142 #endif
Core classes and functionality for both the editor and game.
Adding this component to an entity will allow it to be rendered.
Definition: Renderable.hpp:28
res::WalkAnimations * walkSrc
Definition: Renderable.hpp:126
bl::gfx::a2d::AnimationData * animSrc
Definition: Renderable.hpp:128
static Renderable & createFromAnimation(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component from a single animation.
Definition: Renderable.cpp:71
void setHidden(bool hide)
Set whether the entity is hidden or not.
Definition: Renderable.cpp:144
void setAngle(float angle)
Sets the angle to render the entity at.
Definition: Renderable.cpp:108
bl::com::Transform2D & getTransform()
Returns the render transform.
Definition: Renderable.hpp:114
float animLength() const
Returns the length of the contained animation, or 0.f if no animation.
Definition: Renderable.cpp:110
static Renderable & createFromFastMoveAnims(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component for movement animations with running.
Definition: Renderable.cpp:49
static Renderable & createFromSprite(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component for a static sprite.
Definition: Renderable.cpp:12
res::RunWalkAnimations * runSrc
Definition: Renderable.hpp:127
static Renderable & createFromMoveAnims(bl::engine::Engine &engine, bl::ecs::Entity entity, bl::rc::Scene *scene, const std::string &path)
Creates a renderable component for movement animations.
Definition: Renderable.cpp:28
void triggerAnim(bool loop)
Triggers the current animation if any.
Definition: Renderable.cpp:123
void notifyMoveState(bl::tmap::Direction dir, bool moving, bool running)
Call when the entity starts or stops moving or changes direction.
Definition: Renderable.cpp:130
Extension of animation data that loads and combines the animations for each movement direction into a...
Extension of animation data that loads and combines the animations for each movement direction into a...
Basic system that synchronizes animation states based on movement state events.
Definition: Render.hpp:22