diff options
author | kobewi <kobewi4e@gmail.com> | 2023-01-11 14:08:14 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2023-01-11 14:08:14 +0100 |
commit | f64dd732b8ac249d052519940e46129960e0d771 (patch) | |
tree | af2faabeae41aa9e93260f604442dac996c09f73 | |
parent | da9396881e330e0ec9ede23f9f697da591a1b3c4 (diff) |
Improve some Tween internals
-rw-r--r-- | scene/animation/tween.cpp | 24 | ||||
-rw-r--r-- | scene/animation/tween.h | 3 |
2 files changed, 17 insertions, 10 deletions
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index b88695427e..be8c23844f 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -60,7 +60,7 @@ void Tweener::_bind_methods() { ADD_SIGNAL(MethodInfo("finished")); } -void Tween::start_tweeners() { +void Tween::_start_tweeners() { if (tweeners.is_empty()) { dead = true; ERR_FAIL_MSG("Tween without commands, aborting."); @@ -71,6 +71,15 @@ void Tween::start_tweeners() { } } +void Tween::_stop_internal(bool p_reset) { + running = false; + if (p_reset) { + started = false; + dead = false; + total_time = 0; + } +} + Ref<PropertyTweener> Tween::tween_property(Object *p_target, NodePath p_property, Variant p_to, double p_duration) { ERR_FAIL_NULL_V(p_target, nullptr); ERR_FAIL_COND_V_MSG(!valid, nullptr, "Tween invalid. Either finished or created outside scene tree."); @@ -135,14 +144,11 @@ void Tween::append(Ref<Tweener> p_tweener) { } void Tween::stop() { - started = false; - running = false; - dead = false; - total_time = 0; + _stop_internal(true); } void Tween::pause() { - running = false; + _stop_internal(false); } void Tween::play() { @@ -278,7 +284,7 @@ bool Tween::step(double p_delta) { current_step = 0; loops_done = 0; total_time = 0; - start_tweeners(); + _start_tweeners(); started = true; } @@ -319,7 +325,7 @@ bool Tween::step(double p_delta) { } else { emit_signal(SNAME("loop_finished"), loops_done); current_step = 0; - start_tweeners(); + _start_tweeners(); #ifdef DEBUG_ENABLED if (loops <= 0 && Math::is_equal_approx(rem_delta, initial_delta)) { if (!potential_infinite) { @@ -332,7 +338,7 @@ bool Tween::step(double p_delta) { #endif } } else { - start_tweeners(); + _start_tweeners(); } } } diff --git a/scene/animation/tween.h b/scene/animation/tween.h index 8f65416e71..08911d6623 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -123,7 +123,8 @@ private: typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d); static interpolater interpolaters[TRANS_MAX][EASE_MAX]; - void start_tweeners(); + void _start_tweeners(); + void _stop_internal(bool p_reset); protected: static void _bind_methods(); |