Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- @export var offset: Vector2 = Vector2(0, 0)
- @export var travel_time: float = 2.0
- @export_enum("Linear", "Sine", "Quint", "Quart", "Quad", "Expo", "Elastic", "Cubic", "Circ", "Bounce", "Back")
- var transition_index: int = 0
- @export_enum("Ease In", "Ease Out", "Ease In Out", "Ease Out In")
- var ease_index: int = 0
- var base_position: Vector2
- func _ready() -> void:
- # Store the position you set in the editor as the "start" point.
- base_position = position
- _start_tween_out()
- func _start_tween_out() -> void:
- var tween = create_tween()
- # Move from base_position to base_position + offset
- var track = tween.tween_property(self, "position", base_position + offset, travel_time)
- track.set_trans(_get_transition_constant(transition_index))
- track.set_ease(_get_ease_constant(ease_index))
- tween.tween_callback(Callable(self, "_start_tween_back"))
- func _start_tween_back() -> void:
- var tween = create_tween()
- # Move from base_position + offset back to base_position
- var track = tween.tween_property(self, "position", base_position, travel_time)
- track.set_trans(_get_transition_constant(transition_index))
- track.set_ease(_get_ease_constant(ease_index))
- tween.tween_callback(Callable(self, "_start_tween_out"))
- func _get_transition_constant(index: int) -> int:
- match index:
- 0: return Tween.TRANS_LINEAR
- 1: return Tween.TRANS_SINE
- 2: return Tween.TRANS_QUINT
- 3: return Tween.TRANS_QUART
- 4: return Tween.TRANS_QUAD
- 5: return Tween.TRANS_EXPO
- 6: return Tween.TRANS_ELASTIC
- 7: return Tween.TRANS_CUBIC
- 8: return Tween.TRANS_CIRC
- 9: return Tween.TRANS_BOUNCE
- 10: return Tween.TRANS_BACK
- return Tween.TRANS_LINEAR # Fallback
- func _get_ease_constant(index: int) -> int:
- match index:
- 0: return Tween.EASE_IN
- 1: return Tween.EASE_OUT
- 2: return Tween.EASE_IN_OUT
- 3: return Tween.EASE_OUT_IN
- return Tween.EASE_IN # Fallback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement