Advertisement

SFML getting mouse position

Started by February 14, 2015 05:19 AM
2 comments, last by wintertime 9 years, 11 months ago

I create a render window and set its size to 600 by 600 and whenever I move the window around I get different mouse.getPosition and I was wondering if there is a way to stop this from happening and just make the top left corner 0 for x and 0 for y?

From the documentation.

sf::Mouse::getPosition() gets the mouse position in desktop coordinates.

sf::Mouse::getPosition( Window& ) gets the mouse position relative to the window.

From your description, it looks like you are using the first one but want to be using the second one. Pass in your game window to get the mouse position relative to your window.

Advertisement

Oh thank you!

Just remember the prefered way in SFML is to use sf::Window::pollEvent in a loop and check all input events it gives you anyway.

http://www.sfml-dev.org/tutorials/2.2/window-window.php

http://www.sfml-dev.org/tutorials/2.2/window-events.php

This topic is closed to new replies.

Advertisement