SFML community forums
Help => General => Topic started by: Yours3lf on July 16, 2011, 11:46:20 pm
-
Hi,
I want to warp the mouse, so that the user can move the camera in FPS style.
in SDL there is a function SDL_WarpMoues() which does this. Is there such thing in SFML? Or how is it done in SFML?
Best regards,
Yours3!f
-
SFML 1.6 : sf::Window::SetCursorPosition (http://www.sfml-dev.org/documentation/1.6/classsf_1_1Window.php#a369d1764893c6fde8979fcf04142dc55)
SFML 2 : See sf::Mouse (https://github.com/SFML/SFML/blob/master/include/SFML/Window/Mouse.hpp) (documentation not yet uptodate)
-
wow, ok, I only checked the docs here on sfml-dev.org...
is the one on github better?
anyways thank you!
-
Depending on which version you use (1.6 or 2 ?) you can use sf::Window::SetCursorPosition or sf::Mouse::SetPosition.
I just checked the doxygen documentation for 2.0 on this site and realized that it wasn't up to date so I put the link to the source code. If you're using 2.0 version then I recommend you to build the documentation while compiling SFML. This way you have an local up-to-date version of the documentation.
-
Thanks, I'm going to build the docs definitely. I'm using version 2.
-
ok, I'm having a little bit of problem with this function.
It seems to warp my mouse to:
x coord: middle of the screen
y coord: middle of the screen - mouse height
that is for a 1280x720 window I get the mouse position 640, 340. I don't know if it is an SFML bug or I've done something wrong or it is just the windowing system (Kubuntu 11.04/ KDE), but it is clear that it warps my mouse to that location, because if I move the mouse in a way that in 33 ms (one frame) it moves more than 20-30 pixels then eventually my camera goes down as opposed to always going upwards because of that.
Did anyone have issues like that?
or how can I get the height of the cursor so that I can warp it to the correct position?
Best regards,
Yours3!f
-
I think I solved the problem, I just needed to use
sf::Mouse::SetPosition(pos, window)
instead of
sf::Mouse::SetPosition(pos)
where window was the main window I created.
It seems to set the cursor position to the right location now.