summaryrefslogtreecommitdiff
path: root/addons/escoria-core/game/tween3.gd
diff options
context:
space:
mode:
Diffstat (limited to 'addons/escoria-core/game/tween3.gd')
-rw-r--r--addons/escoria-core/game/tween3.gd56
1 files changed, 37 insertions, 19 deletions
diff --git a/addons/escoria-core/game/tween3.gd b/addons/escoria-core/game/tween3.gd
index 88a3e8a..ee8f07a 100644
--- a/addons/escoria-core/game/tween3.gd
+++ b/addons/escoria-core/game/tween3.gd
@@ -1,7 +1,27 @@
## In Godot 4, tweens cannot be resumed. But if you re-create them,[br]
## the bindings are lost. So this class wraps a tween and offers a reset function.
-extends RefCounted
class_name Tween3
+extends RefCounted
+
+
+## Emitted when the tween finishes.[br]
+## [br]
+## #### Parameters[br]
+## [br]
+## None.
+## [br]
+signal finished()
+
+
+## The parent node for the tween.
+var _tween_parent: Node
+
+## The Tween instance being managed.
+var _tween: Tween
+
+## The duration of the tween.
+var _duration: float
+
## Interpolates a property on an object using a tween.[br]
## [br]
@@ -44,23 +64,6 @@ static func tween_interpolate_property(
return true
-## The parent node for the tween.
-var _tween_parent: Node
-
-## The Tween instance being managed.
-var _tween: Tween
-
-## The duration of the tween.
-var _duration: float
-
-## Emitted when the tween finishes.[br]
-## [br]
-## #### Parameters[br]
-## [br]
-## None.
-## [br]
-signal finished()
-
## Called when the tween finishes.[br]
## [br]
## #### Parameters[br]
@@ -100,7 +103,22 @@ func _init(tween_parent: Node):
## [br]
## Returns nothing.
func _create_tween():
- _tween = _tween_parent.get_tree().create_tween()
+ var tree = _tween_parent.get_tree()
+ if tree == null:
+ escoria.logger.error(
+ self,
+ "Tween3: Parent node is not in the scene tree. Cannot create tween."
+ )
+ return
+
+ _tween = tree.create_tween()
+ if _tween == null:
+ escoria.logger.error(
+ self,
+ "Tween3: Failed to create tween."
+ )
+ return
+
_tween.pause() # prevent autoplay
_tween.finished.connect(_on_finished)