From d48dea71589b8abe255520735586810bdba64bed Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 27 Mar 2022 03:09:12 +0200 Subject: [PATCH] Force final value at the end of Tween --- scene/animation/tween.cpp | 12 +++++++++--- scene/animation/tween.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index a2fed718bee..c8eb270a0ac 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -741,12 +741,12 @@ bool PropertyTweener::step(float &r_delta) { } float time = MIN(elapsed_time - delay, duration); - target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type)); - if (time < duration) { + target_instance->set_indexed(property, tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type)); r_delta = 0; return true; } else { + target_instance->set_indexed(property, final_val); finished = true; r_delta = elapsed_time - delay - duration; emit_signal(SNAME("finished")); @@ -895,8 +895,13 @@ bool MethodTweener::step(float &r_delta) { return true; } + Variant current_val; float time = MIN(elapsed_time - delay, duration); - Variant current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type); + if (time < duration) { + current_val = tween->interpolate_variant(initial_val, delta_val, time, duration, trans_type, ease_type); + } else { + current_val = final_val; + } const Variant **argptr = (const Variant **)alloca(sizeof(Variant *)); argptr[0] = ¤t_val; @@ -938,6 +943,7 @@ MethodTweener::MethodTweener(Callable p_callback, Variant p_from, Variant p_to, callback = p_callback; initial_val = p_from; delta_val = tween->calculate_delta_value(p_from, p_to); + final_val = p_to; duration = p_duration; } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 5b0745b2b3a..62c357dfb44 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -274,6 +274,7 @@ private: Ref tween; Variant initial_val; Variant delta_val; + Variant final_val; Callable callback; };