3 #include <BLIB/Util/FileUtil.hpp>
4 #include <BLIB/Util/Visitor.hpp>
13 bl::rc::Scene* scene,
const std::string& path) {
17 bl::gfx::Sprite sprite;
18 sprite.create(engine, entity, engine.renderer().texturePool().getOrLoadTexture(path));
19 sprite.deleteEntityOnDestroy(
false);
20 sprite.getTransform().setOrigin(sprite.getTexture()->size());
21 sprite.addToScene(scene, bl::rc::UpdateSpeed::Static);
22 rc.transform = &sprite.getTransform();
23 rc.drawable = &sprite.component();
29 bl::rc::Scene* scene,
const std::string& path) {
33 bl::resource::Ref<res::WalkAnimations> data = WalkAnimationManager::getOrCreateGenerated(path);
34 bl::gfx::Slideshow slideshow;
35 slideshow.createWithUniquePlayer(engine, entity, data);
36 slideshow.deleteEntityOnDestroy(
false);
37 slideshow.addToScene(scene, bl::rc::UpdateSpeed::Dynamic);
38 slideshow.getTransform().setOrigin(
41 rc.drawable = &slideshow.component();
42 rc.transform = &slideshow.getTransform();
43 rc.player = &slideshow.getPlayer();
50 bl::rc::Scene* scene,
const std::string& path) {
54 bl::resource::Ref<res::RunWalkAnimations> data =
55 RunWalkAnimationManager::getOrCreateGenerated(path);
56 bl::gfx::Slideshow slideshow;
57 slideshow.createWithUniquePlayer(engine, entity, data);
58 slideshow.deleteEntityOnDestroy(
false);
59 slideshow.addToScene(scene, bl::rc::UpdateSpeed::Dynamic);
60 slideshow.getTransform().setOrigin(
63 rc.drawable = &slideshow.component();
64 rc.transform = &slideshow.getTransform();
65 rc.player = &slideshow.getPlayer();
72 bl::rc::Scene* scene,
const std::string& path) {
74 rc.srcType = SingleAnim;
76 bl::resource::Ref<bl::gfx::a2d::AnimationData> data = AnimationManager::load(path);
78 if (data->isSlideshow()) {
79 bl::gfx::Slideshow slideshow;
80 slideshow.createWithUniquePlayer(engine, entity, data);
81 slideshow.deleteEntityOnDestroy(
false);
82 slideshow.addToScene(scene, bl::rc::UpdateSpeed::Static);
83 rc.drawable = &slideshow.component();
84 rc.transform = &slideshow.getTransform();
85 rc.player = &slideshow.getPlayer();
88 bl::gfx::Animation2D anim;
89 anim.createWithUniquePlayer(engine, entity, data);
90 anim.deleteEntityOnDestroy(
false);
91 anim.addToScene(scene, bl::rc::UpdateSpeed::Static);
92 rc.drawable = &anim.component();
93 rc.transform = &anim.getTransform();
94 rc.player = &anim.getPlayer();
105 , shadow(
bl::ecs::InvalidEntity)
125 if (loop) { player->playLooping(); }
126 else { player->play(); }
132 if (srcType == Walk) {
135 else if (srcType == Run) {
138 if (moving && !isMoving) { player->playLooping(); }
139 else if (!moving) { player->stop(); }
145 if (drawable) { drawable->setHidden(hide); }
Core classes and functionality for both the editor and game.
Adding this component to an entity will allow it to be rendered.
res::WalkAnimations * walkSrc
bl::gfx::a2d::AnimationData * animSrc
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.
void setHidden(bool hide)
Set whether the entity is hidden or not.
void setAngle(float angle)
Sets the angle to render the entity at.
float animLength() const
Returns the length of the contained animation, or 0.f if no animation.
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.
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.
res::RunWalkAnimations * runSrc
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.
void triggerAnim(bool loop)
Triggers the current animation if any.
Renderable()
Does nothing.
void notifyMoveState(bl::tmap::Direction dir, bool moving, bool running)
Call when the entity starts or stops moving or changes direction.
static int PixelsPerTile()
static std::size_t getStateFromDirection(bl::tmap::Direction dir, bool running)
Maps the movement direction to the state index.
float getMaxStateLength() const
Returns the maximum length of any substate animation in seconds.
float getMaxStateLength() const
Returns the maximum length of any substate animation in seconds.
static std::size_t getStateFromDirection(bl::tmap::Direction dir)
Maps the movement direction to the state index.