FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

Cannot figure out how to properly align content with resizing window

I'm trying to create a Godot game that runs in a resizeable window. The larger the window, the more of the game world players should be able to see - i.e. I do not want the game graphics to get scaled up.

The structure of my main scene is as follows:

(A) Node2D
  (B) Camera2D
    (C) Control
  (D) Node2D

(A) is offset by half the viewport width/height as configured in the Project Settings under Display -> Window.

(C) is actually the root of a scene that displays a command bar for controlling the game. It is positioned at the bottom of the viewport.

(D) is the player object.

The camera (B) is set to center on the player object (D) (by means of a RemoteTransform2D).

Dissatisfactory Observation 1

When I run the game, everything looks fine. Once the window is resized (e.g. maximized), the player remains in the center, but I can see a bit more of their surrounding.

However, (C) still has the same position relative to the player object (D). It seems the window gets enlarged to all sides around its former center, rather than e.g. down + right, as I would have intuitively expected.

Now, I can probably reposition (C) programmatically when the window size changes, but I wonder whether I can somehow align (C) automatically to stick to the bottom of the viewport.

I have tried setting anchors_preset for (C) to "Bottom Wide", but that somehow makes (C)'s top left corner snap to the center of the viewport.

Dissatisfactory Observation 2

As some kind of an (almost) screen-filling pop-up, I instantiate a MarginContainer (with the same margin width on all sides) with some controls inside, set its anchors_preset to "Full Rect", and attach it directly to GetTree().Root (i.e. the window itself). This works well in the window's original size.

Once I maximize the window, however, the margin on the right and bottom is gone, and the margin on the left and top have grown considerably, as if the MarginPanel were not anchored to the window at all and had been shifted right and down a bit.


How do I properly anchor my UI controls to a resizeable window?

❌
❌