AnimatedSprite: posibilitat de resetejar o no el estat de la animació en setCurrentAnimation();
This commit is contained in:
@@ -82,7 +82,7 @@ void AnimatedSprite::animate()
|
||||
|
||||
// Si alcanza el final de la animación, reinicia el contador de la animación
|
||||
// en función de la variable loop y coloca el nuevo frame
|
||||
if (animations_[current_animation_].current_frame >= (int)animations_[current_animation_].frames.size())
|
||||
if (animations_[current_animation_].current_frame >= animations_[current_animation_].frames.size())
|
||||
{
|
||||
if (animations_[current_animation_].loop == -1)
|
||||
{ // Si no hay loop, deja el último frame
|
||||
@@ -113,28 +113,48 @@ bool AnimatedSprite::animationIsCompleted()
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name)
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name, bool reset)
|
||||
{
|
||||
const auto new_animation = getIndex(name);
|
||||
if (current_animation_ != new_animation)
|
||||
const auto NEW_ANIMATION = getIndex(name);
|
||||
if (current_animation_ != NEW_ANIMATION)
|
||||
{
|
||||
current_animation_ = new_animation;
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
const auto OLD_ANIMATION = current_animation_;
|
||||
current_animation_ = NEW_ANIMATION;
|
||||
if (reset)
|
||||
{
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size());
|
||||
animations_[current_animation_].counter = animations_[OLD_ANIMATION].counter;
|
||||
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(int index)
|
||||
void AnimatedSprite::setCurrentAnimation(int index, bool reset)
|
||||
{
|
||||
const auto new_animation = index;
|
||||
if (current_animation_ != new_animation)
|
||||
const auto NEW_ANIMATION = index;
|
||||
if (current_animation_ != NEW_ANIMATION)
|
||||
{
|
||||
current_animation_ = new_animation;
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
const auto OLD_ANIMATION = current_animation_;
|
||||
current_animation_ = NEW_ANIMATION;
|
||||
if (reset)
|
||||
{
|
||||
animations_[current_animation_].current_frame = 0;
|
||||
animations_[current_animation_].counter = 0;
|
||||
animations_[current_animation_].completed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
animations_[current_animation_].current_frame = std::min(animations_[OLD_ANIMATION].current_frame, animations_[current_animation_].frames.size());
|
||||
animations_[current_animation_].counter = animations_[OLD_ANIMATION].counter;
|
||||
animations_[current_animation_].completed = animations_[OLD_ANIMATION].completed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user