diff options
author | kobewi <kobewi4e@gmail.com> | 2022-03-27 03:09:12 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-03-27 03:09:12 +0200 |
commit | d48dea71589b8abe255520735586810bdba64bed (patch) | |
tree | a48a91892e22cfb546bac33a313012944875c65c | |
parent | f0407ad14de5e8c4c668ba4e6a983d2211022d9a (diff) |
Force final value at the end of Tween
-rw-r--r-- | scene/animation/tween.cpp | 12 | ||||
-rw-r--r-- | 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 a2fed718be..c8eb270a0a 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 5b0745b2b3..62c357dfb4 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -274,6 +274,7 @@ private: Ref<Tween> tween; Variant initial_val; Variant delta_val; + Variant final_val; Callable callback; }; |