GUI and resolution again

Hey there!

I’ve read some other discussions, and totally don’t get it. Sry. My GUI is set to 1080p resolution by default. And off course if I scale it down, button becoming unreachable while they are actually on screen.

Is there any way to fix that? I don’t use Defold Orthographic. Possibly I’ve done something wrong in render script?

How are you scaling your GUI?

I’m scaling mine using the editor properties in the collection that I’ve put it in and it works fine.

image

1 Like

Thanks! Somehow missed that)

But I’ve encountered quite a number of issues and it makes me think maybe I can make GUI without gui component. I mean with Sprites and Labels. Is it possible or is there something that only GUI can do?

Example: I have a tactical game and it heaviliy depends on mouse cursor. If i move that to upper layer above GUI it totally looses connection to game world, collisions and constantly moving camera. And when it’s in game space, everything works perfect.

you can easily make many GUI components with sprites and labels. If you think that way is easier, you could be right.

1 Like

GUI offers you layout features (anchoring, etc), graphical features (9-slice, stenciling, etc), automatic scaling, and very easy collision detection with nodes. It’s designed for UI. Yes, you can certainly use game objects instead, but you should really think about whether it’s better to rewrite all the built-in GUI features, or to learn how to use them.


For your mouse cursor issues, I suggest you deal with mouse input in your GUI first, since it will be on top and you get the cursor’s GUI position directly from on_input(). If the GUI will use the mouse input (if the cursor is over a button), then it should consume the input so it doesn’t get passed down to the world.

If the GUI does not consume the input, then a script in the game world can use it. First you will need to convert the mouse pos to world space based on your camera (unless your camera will never ever move, zoom, or rotate), and then you can start checking for collisions with your game world objects.

There will probably be some edge cases to this. For example, if you are dragging a world-space object, then you probably don’t want the GUI to use the mouse at all.

5 Likes

Ross, Josh, thanks! I’ll try to fix my conversion functions. Guess I have to stop panicking and give it another try. =)

Haath Nope, nothing changes. My gui is in a screen space, i.e. it shows as needed, but buttons are still beyond the screen space if I lower resolution.

Regarding the scaling issue: you should decide on a fixed, default window size in your game.project, design your GUI in the editor based on that, and not change it. Use your nodes’ pivots, anchors, and adjust modes to make your GUI adapt correctly to different window sizes at runtime.

You can change the window size at runtime with the “resize” message, but if you’re targeting desktop, you will need DefOS (to maximize the window, toggle fullscreen, etc.).

2 Likes

That’s what I did. Just rewrited all render process and it stretches perfectly and keeps all calculations.

So it seems like the only way to fit my game to user display is to stretch it in runtime. And just read there’s no way to change window resolution in runtime. Then how developers fit their games for all android devices screen resolutions?

In my projects I gave up on GUI system and use only game objects. Of course I had to write some amount of code to make it work, but I am very happy with the result. Every object is scaled and positioning according to the current resolution, I can resize game window however I want and all game objects are displayed properly.
Mostly I use a quad model with images on it instead of sprites for the sake of simplicity. Then I set width and height of the game object with model component by setting scale.x and scale.y, which by value get to be equal to pixel size on screen if I use an orthographic projection of window size.

2 Likes

Thanks, Sergey! That’s what i keep thinking about. Maybe some kind of additional library would be a nice alternative until GUI component will be fixed. Do you use the same render layer with only world coordinates?

Oh, thanks! That’s what I needed. It seems like I’ll have to make user to restart the game if resolution changes. But I’m OK with that.

1 Like

I use the same render predicate for all objects and I heavily use parenting of game objects with automatic z ordering depending on children indices.

2 Likes

Solved! Not the most elegant way and it seems like I have to keep separate screen parameters and resolutions switcher, but now it seems like I can use defold GUI with all possible resolution changes. And had to separate logical and visual cursors. But it works fine after all.

Strange, but the app keeps thinking that it works in 1080p on all other resolutions.

Thanks, everyone! :partying_face: