0
\$\begingroup\$

I am programming a game in SDL2 and I am looking for advice on how to handle interactivity of UI components when the screen resolution and logical resolutions are different. Up to now I have been developing the game with common logical and screen solutions, I am working at 2560x1440 and all my UI components (buttons, scroll bars) are defined relative to the screen resolution. If I decide to use SDL_RenderSetLogicalSize to downscale the rendering to say 1920x1080 how should I handle the UI?

If I do nothing, the UI is now off the window screen, I can alternatively set the position of UI components relative to the logical resolution to bring my buttons back within the screen window but then the interactivity is broken - for example the mouse over for a UI box is now checking for a collision at the "logical position" which is different from the screen position.

One thought I had was to keep the UI component positions relative to the screen resolution but at rendering time adjust the drawing of all UI components by the ratio between the logical and screen resolution to make them appear within the window.

My game eventually will have a lot of UI components so before I start putting effort into coding I want to get a sense of what my options are - or if I am going about this the wrong way.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

In case anyone is wondering, I figured it out on my own, the issue was that the mouse position in SDL2 is always given in terms of the screen resolution regardless of what the logical resolution is set to, the solution is to use SDL_RenderWindowToLogical to scale the mouse coordinates appropriately. Then the UI can be completely drawn in terms of the logical resolution and the mouse will react appropriately.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .