Godot Version
4.2
Question
Hello!
The pivot point used by Godot when changing the follow_viewport_scale
attribute of a CanvasLayer
is the middle of the screen, as shown in this simple example:
The script for CanvasLayer
is the following:
extends CanvasLayer
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_accept"):
var tween: Tween = get_tree().create_tween()
tween.tween_property(self, "follow_viewport_scale", follow_viewport_scale * 0.1, 1)
I placed a small red rectangle named Pivot
in the middle of the screen to see the CanvasLayer
shrink towards the middle:
I want to change change this pivot point to an arbitrary point on the window. For instance, using a pivot point in the middle of the Icon
sprite, it would produce something like this:
I scaled down the sprite scale
attribute directly for the previous example, but that is not an option for me.
I tried various things, for instance changing get_viewport().global_canvas_transform.origin
while setting the CanvasLayer
offset
property to the opposite value (one technique I found commonly used to change pivot point), but could not make it work.
Any help appreciated!