All Questions

Community

A
ThePirateKing

Window Resizing

I experimented with resizing the window after this lesson and found that when I did I would start to see well below the level's floor and could even stretch the window width to reveal the entire level in one view. Then upon sizing the window back down to a smaller size, the view was still showing beyond the floor somewhat. Additionally, while expanding the window the background remained a constant size and did not expand; so with a large width window I could see half the level without any background.

As per the earlier lessons I have the following settings for the window:
Width = 1920
Height = 1080
Test Width = 1280
Test Height = 720
Mode = 2d
Aspect = expand

Are there any strategies to address this, such that the window won't expand beyond certain limits such as the camera's view, or that the background would expand with the window?
Perhaps the window shouldn't be resizable?

  • Nathan Lovato replied

    To prevent the view from going below the level's floor, you can use the camera node's limit properties. As long as your level has clear bounds, this will force the camera view not to go past them. I thought we showed it somewhere in the course, but I'm not sure as it's been a long time since I recorded it.

    When you change the camera's limit properties, you'll see a yellow rectangle appear in the viewport, which helps to visualize their effect.

    Regarding the project settings, instead of using the 2D mode, when shipping a game, you may want to use the viewport mode, and yes, maybe prevent manual window resizing. Also, while I like the expand mode, it won't work, for example, on really wide screens or when the screen ratio becomes too extreme. Which happens when the player can resize the window freely.

    The viewport window mode renders the game at a given resolution and the resulting texture then gets mapped to the window.

    Most released games use that kind of rendering mode and provide the player with a limited list of allowed resolutions. You've certainly seen those option menus where you cycle through a dozen or more possible render resolutions.

    The 2D mode and allowing resizing are good for testing, though, so you can see if your UI anchors work as expected, for instance, by resizing the window interactively. I mostly use them for development and testing.