Entities in the world are now animated like before using the new animation system.
This commit is contained in:
parent
594be65f45
commit
779599f030
9 changed files with 85 additions and 79 deletions
|
|
@ -101,15 +101,15 @@ void Raycaster::apply_sprite_effect(shared_ptr<sf::Shader> effect, float width,
|
|||
effect->setUniform("u_resolution", u_resolution);
|
||||
}
|
||||
|
||||
inline void step_animation(DinkyECS::World& world, DinkyECS::Entity entity, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale, sf::IntRect& in_texture, sf::Vector2f& origin) {
|
||||
auto anim = world.get_if<animation::Animation>(entity);
|
||||
|
||||
if(anim != nullptr && anim->playing) {
|
||||
anim->update();
|
||||
anim->apply(sprite, in_texture);
|
||||
anim->motion(sprite, position, scale);
|
||||
}
|
||||
inline void step_animation(animation::Animation& anim, sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale, sf::IntRect& in_texture, sf::Vector2f& origin) {
|
||||
anim.update();
|
||||
anim.apply(sprite, in_texture);
|
||||
anim.motion(sprite, position, scale);
|
||||
sprite.setOrigin(origin);
|
||||
sprite.setTextureRect(in_texture);
|
||||
}
|
||||
|
||||
inline void set_scale_position(sf::Sprite& sprite, sf::Vector2f& position, sf::Vector2f& scale, sf::IntRect& in_texture, sf::Vector2f& origin) {
|
||||
sprite.setScale(scale);
|
||||
sprite.setPosition(position);
|
||||
sprite.setOrigin(origin);
|
||||
|
|
@ -218,7 +218,13 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) {
|
|||
effect->setUniform("darkness", level);
|
||||
}
|
||||
|
||||
step_animation(*world, rec.entity, *sf_sprite, position, scale, in_texture, origin);
|
||||
auto anim = world->get_if<animation::Animation>(rec.entity);
|
||||
|
||||
if(anim != nullptr && anim->playing) {
|
||||
step_animation(*anim, *sf_sprite, position, scale, in_texture, origin);
|
||||
} else {
|
||||
set_scale_position(*sf_sprite, position, scale, in_texture, origin);
|
||||
}
|
||||
|
||||
target.draw(*sf_sprite, effect.get());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue