63 lines
1.6 KiB
GDScript
63 lines
1.6 KiB
GDScript
@tool
|
|
extends Node
|
|
class_name ControlAnimationPlayer
|
|
|
|
@onready var target : Control = get_parent()
|
|
|
|
@export_tool_button("Test Shake", "Callable") var shake_action = shake
|
|
@export_tool_button("Test Bounce", "Callable") var bounce_action = bounce
|
|
|
|
func bounce(
|
|
duration : float = 0.4,
|
|
amount : float = 10,
|
|
direction : Vector2 = Vector2.UP,
|
|
transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_BOUNCE,
|
|
):
|
|
await add_tween(
|
|
"position",
|
|
target.position + direction * amount,
|
|
duration/2,
|
|
transition_type
|
|
).finished
|
|
await add_tween(
|
|
"position",
|
|
target.position - direction * amount,
|
|
duration/2,
|
|
transition_type
|
|
).finished
|
|
|
|
func shake(
|
|
duration : float = 0.3,
|
|
amount : float = 10,
|
|
transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_LINEAR,
|
|
):
|
|
await add_tween(
|
|
"position",
|
|
target.position + Vector2.RIGHT * amount/2,
|
|
duration/3,
|
|
transition_type
|
|
).finished
|
|
await add_tween(
|
|
"position",
|
|
target.position + Vector2.LEFT * amount,
|
|
duration/3,
|
|
transition_type
|
|
).finished
|
|
await add_tween(
|
|
"position",
|
|
target.position + Vector2.RIGHT * amount/2,
|
|
duration/3,
|
|
transition_type
|
|
).finished
|
|
|
|
|
|
func add_tween(
|
|
property : String,
|
|
value : Variant,
|
|
seconds: float = 1.,
|
|
transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_LINEAR
|
|
) -> Tween:
|
|
var tween : Tween = get_tree().create_tween()
|
|
tween.set_trans(transition_type)
|
|
tween.tween_property(target, property, value, seconds)
|
|
return tween |