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

get_viewport_rect().size

1 Answer

0 votes
Best answer
tool
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)
    else:
        rect_rotation = 0
        rect_scale = Vector2(win.x / tex.x, win.y / tex.y)

https://gotm.io/henry-software/pixelleveltest

by (1,665 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 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 webmaster@godotengine.org with your username.