Browse Source

Merge pull request #22712 from groud/fix_animation_finished_signal

Fixes AnimatedSprite2D animation_finished signal triggering too early
Rémi Verschelde 7 years ago
parent
commit
ea65a1bbb3
2 changed files with 8 additions and 3 deletions
  1. 7 3
      scene/2d/animated_sprite.cpp
  2. 1 0
      scene/2d/animated_sprite.h

+ 7 - 3
scene/2d/animated_sprite.cpp

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

+ 1 - 0
scene/2d/animated_sprite.h

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