SFML community forums

Help => Window => Topic started by: Tomasz on August 26, 2022, 05:19:07 pm

Title: Problem with mouse position
Post by: Tomasz on August 26, 2022, 05:19:07 pm
Hi,
I have a problem with my cursor position when I use the "sf :: View view" camera control my cursor loses its real position.

when I don't use "view" the cursor matches its coordinates,
but when I create a view, the coordinates are completely different from the cursor. And the view follow the object, and the object follows the cursor and when the cursor coordinates do not match, I have no control over the object.

in the photos I marked the cursor with white.
On the 13th photo I am using view.
At 14h photo, I don't use view
Title: Re: Problem with mouse position
Post by: G. on August 26, 2022, 07:28:17 pm
Your cursor has a position in pixels, relative to the screen or the window. Entities inside your game have coordinates in "world units".
If you want to convert your mouse position in pixels to its corresponding coordinates in the game world, use the mapPixelsToCoords function
https://www.sfml-dev.org/tutorials/2.5/graphics-view.php#coordinates-conversions