Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with mouse position  (Read 399 times)

0 Members and 1 Guest are viewing this topic.

Tomasz

  • Newbie
  • *
  • Posts: 1
    • View Profile
Problem with mouse position
« 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
« Last Edit: August 26, 2022, 05:21:24 pm by Tomasz »

G.

  • Hero Member
  • *****
  • Posts: 1567
    • View Profile
Re: Problem with mouse position
« Reply #1 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