I’m adding the first simple UI elements to my 2D Godot game (screenshots here) I probably only need a couple of buttons, nothing else.
But I have a wrinkle, which is that the game subtly uses polar co-ordinates, and the on-screen “mouse cursor” crosshairs are drawn by me, and are moved by the user’s relative mouse movements, such that when the user moves left or right, the crosshairs move, and the screen scrolls sideways somewhat too, and both of them track the planet’s curved surface along the bottom edge of the screen. This means that the on-screen position of the visible crosshairs differs substantially from that of the invisible (captured) mouse.
In my ignorance about how Godot’s UI elements work, I’m worried that this disconnect between the actual mouse cursor and my visible crosshairs will make it difficult for me to use regular Godot UI elements. In particular, make it fiddly for me to “light up” a button when the crosshairs move over them (like a javascript ‘mouseover’ highlight).
I’ll also be keen to control the rendering of the buttons, so I’ll have to figure out Themes, too. Clearly this is eminently do-able, but since I only need a couple of buttons, I’m currently tempted to just to write my own Button class instead, which draws some text with a rectangle around it, adds a collision rect in screen-space, and highlights itself when the center of the crosshairs goes over it. From my current scanty knowledge of Godot, this seems much easier.
I’m only adding these buttons for things like ‘fullscreen’ toggle button, so that my web export will be able to successfully go fullscreen because it is in response to a user-input event. I also support Linux and Windows exports.
Any advice about which way to jump gratefully received.
Thank you! I don’t know how I overlooked this while reading through the documentation. I guess I was focused on the UI docs, not the Input docs. Many thanks!
Thanks for the reassurance. Your comment made me go back to start converting my other code which draws text on the screen, for which I was just calling draw_string() in my own Node2D instances, and converted them to Label UI elements instead. This has started my familiarity with the UI paradigms and containers and using a default theme. The only thing I was still missing was the suggestion from @normalized to use ‘Input.warp_mouse’, which sounds like it will solve my last remaining problem with buttons.
I have found that the Godot UI system is actually very pleasant to work with and it’s really not a bad thought to use it to build a “normal” non-gaming application.
Gah, now I come to sit down and implement this, I notice that Input.warp_mouse
“has no effect” on web exports. This whole exercise is just to overhaul my minimal UI so that web exports will run.
Thanks for the thoughts, but it sounds like I need a totally different approach. Either write the ‘cursor-over’ detection myself, or maybe abandon buttons altogether, and just use a key press handler…