diff --git a/includes/FastEngine/accessor/C_animation.hpp b/includes/FastEngine/accessor/C_animation.hpp index 8d848c8e..07e5ef99 100644 --- a/includes/FastEngine/accessor/C_animation.hpp +++ b/includes/FastEngine/accessor/C_animation.hpp @@ -81,6 +81,9 @@ class FGE_API Animation : public manager::BaseDataAccessor< /** * \brief Set the group of the animation by its name * + * If the frame index overflow in the new group, it will be reset to 0. + * Else the frame index will be kept. + * * \param group The name of the group * \return \b true if the group was found, \b false otherwise */ @@ -88,6 +91,9 @@ class FGE_API Animation : public manager::BaseDataAccessor< /** * \brief Set the group of the animation by its index * + * If the frame index overflow in the new group, it will be reset to 0. + * Else the frame index will be kept. + * * \param groupIndex The index of the group * \return \b true if the group was found, \b false otherwise */ diff --git a/sources/accessor/C_animation.cpp b/sources/accessor/C_animation.cpp index 2a85ed9a..0f1ac331 100644 --- a/sources/accessor/C_animation.cpp +++ b/sources/accessor/C_animation.cpp @@ -83,7 +83,6 @@ bool Animation::setGroup(std::string_view group) { //Same group if (data->_groups[this->g_groupIndex]._groupName == group) { - this->g_frameIndex = 0; return true; } } @@ -93,7 +92,10 @@ bool Animation::setGroup(std::string_view group) if (data->_groups[i]._groupName == group) { this->g_groupIndex = i; - this->g_frameIndex = 0; + if (this->g_frameIndex >= data->_groups[i]._frames.size()) + { + this->g_frameIndex = 0; + } return true; } } @@ -103,14 +105,17 @@ bool Animation::setGroup(Index groupIndex) { if (this->g_groupIndex == groupIndex) { //Same group - this->g_frameIndex = 0; return true; } - if (groupIndex < this->retrieve()->_groups.size()) + auto data = this->retrieve(); + if (groupIndex < data->_groups.size()) { this->g_groupIndex = groupIndex; - this->g_frameIndex = 0; + if (this->g_frameIndex >= data->_groups[groupIndex]._frames.size()) + { + this->g_frameIndex = 0; + } return true; } return false;