0 votes

I've made a system that change the CanvasLayers offset to smoothly change between screens, like a scrolling effect. But, this only works on the default resolution (320x180). How I can change the offsets based on the game resolution, since it'll be scaled to the device resolution? (For example, this works on 1280x720 because it's in the same aspect ratio, but don't work on ultrawide )
All the screens
The offsets math is: -320*n

The problem

One of the solutions is changing all the offsets on _ready() to fit the aspect ratio of the game, but since the default resolution is low, I can't find a way to do this.

in Engine by (41 points)
edited by


1 Answer

0 votes
Best answer
extends Control

func _ready() -> void:
    Utility.ok(get_node("..").connect("resized", self, "_onResized"))

func _onResized() -> void:
    var tex := rect_size
    var win := get_viewport_rect().size
    if win.x > win.y:
        rect_rotation = 90
        rect_scale = Vector2(win.y / tex.x, win.x / tex.y)
        rect_rotation = 0
        rect_scale = Vector2(win.x / tex.x, win.y / tex.y)


by (1,880 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.