diff --git a/examples/animation/src/main.cpp b/examples/animation/src/main.cpp index b05efba..af6b203 100644 --- a/examples/animation/src/main.cpp +++ b/examples/animation/src/main.cpp @@ -19,18 +19,20 @@ class PlayerEntity : public simpleengine::Entity { private: sf::Sprite sprite; sf::Texture texture; - float movement_speed = 150; + float movement_speed = 130; sf::Vector2u window_size; std::unique_ptr move_anim_component; public: explicit PlayerEntity(sf::Vector2u window_size) : window_size(window_size) { texture.loadFromFile("player_sheet.png"); + texture.setSmooth(true); sprite.setTexture(texture); + sprite.setScale(.7, .7); move_anim_component = std::make_unique(*this, sprite, texture, movement_speed, 5, 1.1); - move_anim_component->SetAnimation(simpleengine::MovementAnimationType::WALK_LEFT, 9, 0, 8, + move_anim_component->SetAnimation(simpleengine::MovementAnimationType::WALK_LEFT, 8, 0, 8, 9, 8, 128, 128); move_anim_component->SetAnimation(simpleengine::MovementAnimationType::IDLE_LEFT, 20, 0, 0, 6, 0, 128, 128); diff --git a/include/simpleengine/animation.h b/include/simpleengine/animation.h index 435f0ff..31a9a06 100644 --- a/include/simpleengine/animation.h +++ b/include/simpleengine/animation.h @@ -36,6 +36,7 @@ namespace simpleengine { sf::IntRect start_rect; sf::IntRect current_rect; sf::IntRect end_rect; + sf::Vector2f start_scale; bool horizontally_flipped = false; bool vertically_flipped = false; diff --git a/src/animation.cpp b/src/animation.cpp index fc54b95..7d8f11e 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -16,9 +16,10 @@ simpleengine::Animation::Animation(sf::Sprite &sprite, sf::Texture &texture_shee // Set start of sprite. this->sprite.setTexture(texture_sheet, true); this->sprite.setTextureRect(start_rect); + this->start_scale = sprite.getScale(); this->current_rect = start_rect; - sprite.setOrigin({ static_cast(sprite.getLocalBounds().width * .5), 0 }); + sprite.setOrigin({ static_cast(sprite.getLocalBounds().width * 0.5), 0 }); } void simpleengine::Animation::Update(const float& delta_time) { @@ -45,23 +46,15 @@ void simpleengine::Animation::Reset() { } void simpleengine::Animation::FlipHorizontally() { - if (!horizontally_flipped) { - sprite.setScale(-1, 1); - horizontally_flipped = true; - } else { - sprite.setScale(1, 1); - horizontally_flipped = false; - } + sf::Vector2f scale = sprite.getScale(); + sprite.setScale(-scale.x, scale.y); + horizontally_flipped = !horizontally_flipped; } void simpleengine::Animation::FlipVertically() { - if (!vertically_flipped) { - sprite.setScale(1, -1); - vertically_flipped = true; - } else { - sprite.setScale(1, 1); - vertically_flipped = false; - } + sf::Vector2f scale = sprite.getScale(); + sprite.setScale(scale.x, -scale.y); + vertically_flipped = !vertically_flipped; } bool simpleengine::Animation::IsHorizontallyFlipped() const { diff --git a/src/components/ssma_component.cpp b/src/components/ssma_component.cpp index 3e1dcf0..be0c738 100644 --- a/src/components/ssma_component.cpp +++ b/src/components/ssma_component.cpp @@ -6,6 +6,8 @@ #include "components/ssma_component.h" +#include + simpleengine::SideScrollerMovementAnimationComponent::SideScrollerMovementAnimationComponent(simpleengine::Entity &owning_entity, sf::Sprite &sprite, sf::Texture &texture_sheet, float max_velocity, float acceleration, float deceleration) : Component(owning_entity), anim_component(owning_entity, sprite, texture_sheet), @@ -73,9 +75,6 @@ void simpleengine::SideScrollerMovementAnimationComponent::Update(const float& d anim.Update(delta_time); } else { Animation& anim = anim_component.GetAnimation("IDLE_LEFT"); - if (!anim.IsHorizontallyFlipped()) { - anim.FlipHorizontally(); - } anim.Update(delta_time); } } else { @@ -89,9 +88,6 @@ void simpleengine::SideScrollerMovementAnimationComponent::Update(const float& d anim.Update(delta_time); } else { Animation& anim = anim_component.GetAnimation("IDLE_RIGHT"); - if (!anim.IsHorizontallyFlipped()) { - anim.FlipHorizontally(); - } anim.Update(delta_time); } }