Aspect ratio control

My game runs fine with any aspect ratio >= 1 (i.e. horizontal window).

According to your experience as a developer/player, is it sensible to resize the game window if the aspect ratio is too low to keep it above a minimum? Or would the player perceive this as unpleasant?

Thanks for any suggestion!

I don’t think it’s sensible. There’s a lot of setups where the user can’t resize the window (the dock is in the way, fullscreen, etc.), you can’t know if it’s safe to resize it to be smaller/bigger, it might cause UX issues if you resize the window while the user is actively dragging it. I’d avoid it. What we do is that we add horizontal/vertical letterboxing if the aspect ratio is outside the aspect ratio range supported by the game (by restricting the GL viewport). This messes up your coordinates a bit, but we have a module to account for that.

EDIT: Example here for a fixed aspect ratio, but you can calculate viewport_width and viewport_height to be whatever.

1 Like

@dapetcu21 Thank you!

Your suggestion is the unique alternative I had in mind. I will implement vertical letterboxing if the aspect ratio is too low. I use a coordinate system with origin in the center of the screen and fixed vertical size. It should not be so difficult to let the render adjust the viewport.

The difficulty is with the GUI. If you want that letterboxed as well, you need to do some custom layouting and messing with the proj matrix for it to match input action coordinates and all. The GUI system is not aware it’s being rendered in a smaller viewport and you need to adjust for that.

2 Likes

Thanks again!

By “GUI” do you mean “Defold gui system”? I never use defold gui api.

The mouse input is already mapped to logical coordinates. This should be probably somehow improved, but I don’t expect many problems in this point. :slight_smile:

Have I already said that sometime I am over-optimistic? :smile:

2 Likes

Then it sounds like, for the most part, you’re good to go. When we did this, GUI was the only issue. The rest of the game pretty much worked out of the box (we were mapping all the input coords with the Layout module anyway).

1 Like

I will report here any particular problem I need to solve. Just for future users.

I prefer to use as few external modules as possible. I feel like I spend more time learning how to use other people’s modules than writing my own. Of course most of the time this is false, but I always have difficulty studying something while I enjoy the challenge of solving problems

Everyone has his faults! :smile:

Thanks!

3 Likes

Sure. Go for it! Use whatever’s comfortable. I was not trying to sell my modules. Just linking to how we solved the same problem. I prefer to roll my own stuff as well, mostly because I know I will end up needing a very particular and custom thing that the original maintainer didn’t think about and it’s easier if the module was built from the ground up to be tailored for the use-case. Apart from native extensions, Interrogation probably only uses RichText as a 3rd party library (and a few PRs were due there as well). Ever since we also adopted Monarch for scene management in our more recent projects (the solution we used in Interrogation was doing pretty much the same thing and was more clunky).

2 Likes

As you probably already know I use your defold-fmod extension! Without it I would be totally lost for audio… I use defos, also this is yours, right? and finally PlayFab for leadearboard.

In my dreams in the long distant future I see: (1) defold builds for Playstation / XBox and (2) some kind of ECS for Defold. If (1) becomes reality I would like to try to implement (2) with some kind of native extension. But at the moment I am not able of even building defold from source, so very long distant future.

But I hope we have (1) some days, since I tried Unity and I don’t like it at all. Probably also Unity doesn’t like me :slight_smile:

3 Likes

Hi! I have finally implemented the vertical letterboxing as @dapetcu21 suggested. It took some work but now rendering and input are woking fine!

However, I have to make a further change. I was using defos to hide/show the hardware cursor when the mouse cursor was outside/inside the game window. And I was using a normal go to show a custom cursor. Now this approach is no more possible: the letterboxing is implemented narrowing the viewport, so I cannot move the cursor outside the game area in the game window.

This forces me to change the hardware cursor (if I want a custom cursor at all).

It’s definitely better to have a hardware cursor. Having the 1-frame latency your software cursor is subjected to is not great UX. Makes it feel like you’re fighting the controls a little bit. We have one in Interrogation and Domains of Dusk. It is a bit of work though. You need to make cursors for macOS/Windows/Linux individually and it’s a bit of a kludge on windows where you have to actually store the cursor to a file before you can use it, but maybe we can improve that in DefOS somehow.

1 Like

@dapetcu21 Thank you for all your suggestions! I will try to implement a hardware cursor first on Mac, then on Windows and finally on Linux.

1 Like

An extra tip: When doing your Windows cursor, test your cursor on Windows 7 as well (use one of the MS-provided Internet Explorer VMs). Windows 7 is pickier than Windows 10 when it comes to cursor resolutions.

1 Like