瀏覽代碼

Improve some Tween internals

kobewi 2 年之前
父節點
當前提交
f64dd732b8
共有 2 個文件被更改,包括 17 次插入10 次删除
  1. 15 9
      scene/animation/tween.cpp
  2. 2 1
      scene/animation/tween.h

+ 15 - 9
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();
 			}
 		}
 	}

+ 2 - 1
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();