Godot - Implement zoom in/out animation with Tween
Code example to implement zoom in/out animation using Tween in GDScript.
It is possible to implement zooming in/out using Tween.
Create a new Tween with create_tween()
, and create a "scale" change animation with tween_property()
.
If zooming the entire game screen, create the Tween on the root node.
If zooming only specific objects, create the Tween on the target nodes.
# tween_property(target node, "scale", Vector2(ScaleX, ScaleY), duration)
# Zoom in
var tween = create_tween()
tween.tween_property(self, "scale", Vector2(5, 5), 1)
tween.play()
# Zoom out
var tween = create_tween()
tween.tween_property(self, "scale", Vector2(0.1, 0.1), 1)
tween.play()