0 votes

I'm coming from unity and I try to port one of my old prototypes to godot. It is a mobile game. When developing for mobile it is important to respect multiple aspect ratios.
In unity my scaling worked the way that the width of the shown area was constant. The height is set based on this. It is basicly the scaling behavior you get when adding an ortagonal 3d camera and set the scaling mode of the camera to keep width.
But my game is 2d and therefore I have to use the 2d mode. When using it you can set the scaling mode in the project settings to keep_width as well. But there is a difference to the 3d scalling behavior. In 3d the height of the visible area can get less than it started. But in 3d the height of the visible area can only get bigger and when the window is to width there are black bars added instead of decreasing the height.

Is there a way to achieve the scaling behaviour of the 3d camera with 2d.

Edit:
I hope it is understandable what i mean. If not feel free to ask. I would add images but I dont know how. The image options only allows for urls.

Godot version 3.2.3.stable
in Engine by (334 points)

2 Answers

0 votes
Best answer

Use the 2d stretch mode and expand stretch aspect, and make sure to configure anchors correctly in your UI nodes to support multiple aspect ratios. See Multiple resolutions in the documentation.

Is there a way to achieve the scaling behaviour of the 3d camera with 2d.

You can still adjust the camera zoom to compensate for different screen resolutions manually. Basically, you can multiply the camera zoom value by the scale factor.

by (12,889 points)
selected by
0 votes

Here is a litle script to solve this.

extends Camera2D

var base_width

func _ready():
    base_width = ProjectSettings.get_setting("display/window/size/width")
    get_tree().get_root().connect("size_changed", self, "calc_size")
    calc_size()

func calc_size():
    var s = base_width / get_viewport_rect().size.x

    zoom.x = s
    zoom.y = s
by (334 points)
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.