From b3eae9ebdfe024548a4683b38ba4ecd869338854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Wed, 2 Jun 2021 16:11:14 +0200 Subject: [PATCH] adding the possibility to pause/resume an animation --- .../Component/Animation/AnimationsComponent.cpp | 15 +++++++++++++-- .../Component/Animation/AnimationsComponent.hpp | 10 +++++++++- sources/System/Animation/AnimationsSystem.cpp | 2 ++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sources/Component/Animation/AnimationsComponent.cpp b/sources/Component/Animation/AnimationsComponent.cpp index 843dcbcc..72be399f 100644 --- a/sources/Component/Animation/AnimationsComponent.cpp +++ b/sources/Component/Animation/AnimationsComponent.cpp @@ -8,10 +8,11 @@ namespace BBM { - AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex) + AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play) : WAL::Component(entity), _modelAnimation(std::move(modelAnimation)), - _currentAnimIndex(animIndex) + _currentAnimIndex(animIndex), + _animDisabled(play) { this->_modelAnimation[this->_currentAnimIndex].setFrameCounter(0); } @@ -57,4 +58,14 @@ namespace BBM { this->_modelAnimation[this->_currentAnimIndex].incrementFrameCounter(); } + + void AnimationsComponent::setAnimDisabled(bool disable) + { + this->_animDisabled = disable; + } + + bool AnimationsComponent::isAnimDisabled() const + { + return this->_animDisabled; + } } \ No newline at end of file diff --git a/sources/Component/Animation/AnimationsComponent.hpp b/sources/Component/Animation/AnimationsComponent.hpp index ffaf0599..62e2e13b 100644 --- a/sources/Component/Animation/AnimationsComponent.hpp +++ b/sources/Component/Animation/AnimationsComponent.hpp @@ -18,6 +18,8 @@ namespace BBM RAY::ModelAnimations _modelAnimation; //! @brief The index of the int _currentAnimIndex; + //! @brief Bool allowing to play pause an animation + bool _animDisabled; public: //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; @@ -43,8 +45,14 @@ namespace BBM //! @brief Increment the internal anim counter void incCurrentAnimFrameCounter(); + //! @brief Allow to play pause animations + void setAnimDisabled(bool disable); + + //! @brief To know if the animation will be updated or not + bool isAnimDisabled() const; + //! @brief ctor entity and the path of the animation file - explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex); + explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play = true); //! @brief copy ctor AnimationsComponent(const AnimationsComponent &) = default; //! @brief dtor diff --git a/sources/System/Animation/AnimationsSystem.cpp b/sources/System/Animation/AnimationsSystem.cpp index 66d1253e..7e54adbd 100644 --- a/sources/System/Animation/AnimationsSystem.cpp +++ b/sources/System/Animation/AnimationsSystem.cpp @@ -24,6 +24,8 @@ namespace BBM auto &model = entity.getComponent>(); auto &anim = entity.getComponent(); + if (anim.isDisabled()) + return; model.member.setAnimation(anim.getCurrentModelAnim()); anim.setCurrentAnimFrameCounter(anim.getCurrentAnimFrameCounter() + 1); }