Let's say I have this code where I have a 1920x1080 window and a 50x50 button sprite at position.x 1800 position.y 1000
V = sf::Mouse::getPosition(WINDOW);
if ((V.x >= 1800) && (V.x <= 1850) && (V.y >= 1000) && (V.y <= 1050)) { press_button(); }
It works as intended at the original resolution; but if I were to change the window's resolution to something else like 1280x720, it won't work because even though my mouse is hovering over the same area on the resized window, the mouse-window coordinates are not the same.
Checking for whether the button's bounds contains the mouse is not always an option because let's say I want to use a single sprite and get different results when I click on different parts of that one sprite. (or because I've already coded the whole thing like this
)
Is there a way to make this code for a window of any size without making the sprite bounds check for the mouse position?