Merge pull request #22712 from groud/fix_animation_finished_signal

Fixes AnimatedSprite2D animation_finished signal triggering too early
This commit is contained in:
Rémi Verschelde 2018-10-07 11:17:14 +02:00 committed by GitHub
commit ea65a1bbb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -395,15 +395,17 @@ void AnimatedSprite::_notification(int p_what) {
int fc = frames->get_frame_count(animation);
if (frame >= fc - 1) {
if (frames->get_animation_loop(animation)) {
emit_signal(SceneStringNames::get_singleton()->animation_finished);
frame = 0;
} else {
if (!is_over) {
emit_signal(SceneStringNames::get_singleton()->animation_finished);
is_over = true;
}
frame = fc - 1;
}
} else {
frame++;
if (frame == fc - 1) {
emit_signal(SceneStringNames::get_singleton()->animation_finished);
}
}
update();
@ -625,6 +627,7 @@ void AnimatedSprite::_reset_timeout() {
return;
timeout = _get_frame_duration();
is_over = false;
}
void AnimatedSprite::set_animation(const StringName &p_animation) {
@ -712,4 +715,5 @@ AnimatedSprite::AnimatedSprite() {
playing = false;
animation = "default";
timeout = 0;
is_over = false;
}

View File

@ -135,6 +135,7 @@ class AnimatedSprite : public Node2D {
bool centered;
Point2 offset;
bool is_over;
float timeout;
bool hflip;