I'm working on a 2D project and am trying to achieve the following:

  • Game has a minimum width/ height; if the window is smaller than that, exit with error message
  • Game has an up-to width/ height; up to this size, additional content will be shown
  • Game has a maximum width/ height; above this size, black bars will be shown
  • Game allows resizing of the window and adapts to the new size on-the-fly

I'm struggling. Particularly, the following problems/ questions arise:

  • What's the right/ best root node to use? I'm currently using Node as it is the most generic
  • How can I make a container not exceed the maximum width/ height?
  • What parts of the setup should I try to set up via UI (container/ control) nodes and their properties, which should be done with code?
  • Currently, I'm trying to set the rect_size of containers to the root's size (= window size?), but they simply resize to be able to contain larger child nodes; instead I'd like child nodes to shrink to adapt to the parent container; how?

Sorry, lots of questions, quite chaotic. But that mirrors what's going on in my head. I'm a noob, please don't decapitate me. Any pointers are appreciated.

Game has a minimum width/ height; if the window is smaller than that, exit with error message

Doing so is bad practice in terms of accessibility. I wouldn't recommend ever doing that. Very few games/applications actually do something like that. Instead, your game/application should attempt to scale to any display in a best-effort manner.

  • Game has an up-to width/ height; up to this size, additional content will be shown
  • Game has a maximum width/ height; above this size, black bars will be shown
  • Game allows resizing of the window and adapts to the new size on-the-fly

Use the 2d stretch mode and keep_width stretch aspect as described in the multiple resolutions documentation.

Doing so is bad practice in terms of accessibility.

I was thinking to only error out for ridiculously small windows, for example smaller than 60 pixels or so. But I still agree, that's not a great thing to do.

Use the 2d stretch mode and keep_width stretch aspect as described in the multiple resolutions documentation.

That's very useful and seems to take care of most of my requirements, just not the "up-to" size. Bit hard to explain, but let's say my background asset is 1920x1080 px. However, only the center 1280x720 px of that is actually essential to the game. If a user's window is 1280x720, they would see exactly that essential part. If their window is bigger in one or both directions, additional parts of the background asset would be used. At 1920x1080, the entire background asset would be shown. Only if the user's window size exceeds 1920x1080 would I want the entire content to stretch to fit and show black bars where required.

Does that make sense? Is there a way to achieve this? I could whip up code for it, but I don't know how to programmatically mess with the entire scale mode, root window size, container size. It seems whatever I set for rect_size, for example, will be discarded right away if the container's content is larger.

a year later