-
Hi. Im using sfml for implementing fps style camera and Ive recently noticed some strange behaviour. Code structure looks like this
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 720), "test");
// ...
// ...
// main loop
while(!exitLoop)
{
//...
sf::Vector mousePosition = sf::Mouse::getPosition(window);
sf::Mouse::setPosition(sf::Vector2i(640, 360), window);
update(mousePosition);
// ...
}
}
The thing is I use laptop with another monitor. When I set laptop window as a main screen and run an app, everything works fine. But when I set my second monitor as a main screen, sometimes setting the mouse into the center of a screen actually sets the mouse position into slightly diffrent values like (639, 360), (640, 359) etc...which causes some small offset against the center and constantly moves my camera, even when Im not touching my mouse. Sorry if its some stupid mistake. Thanks for help.
-
And how do you check that it's not at the specified position?
What OS are you using? What SFML version are you using?
-
immediately after setPosition
std::cout << sf::Mouse::getPosition(window).x << " " << sf::Mouse::getPosition(window).y << std::endl;
Working on Windows 10 and sfml 2.4.0
-
I think to understand the issue we need a minimal, yet complete, program that reproduces this issue, as well as specifics about your setups. Also, update your SFML version. ;)
In this discussion (https://github.com/SFML/SFML/pull/614#issuecomment-81080916) an alternative API for mouse relative movements was discussed ("fps-style"). I'm not saying that we need it -- maybe there's a slight bug in your code or we need to tweak SFML implementation -- but if it appears from the minimal & complete example that it cannot be solved with the current API, we might need to consider discussing this alternative API a bit more.
-
Updated to latest version, now Im using 2.4.2 64 bit version compiled under VS 2015...and its definitely not a problem of my code, which manages my camera...made this little program:
#include <SFML\Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 720), "Test", sf::Style::Default);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
window.close();
}
sf::Vector2i mousePosition = sf::Mouse::getPosition(window);
sf::Mouse::setPosition(sf::Vector2i(640, 360), window);
std::cout << sf::Mouse::getPosition(window).x << " " << sf::Mouse::getPosition(window).y << std::endl;
window.clear();
window.display();
}
return EXIT_SUCCESS;
}
...and bug is still there...on my laptop monitor it works fine but when I switch to second monitor and moves a mouse a little, it is centered at wrong position and stays there while not moving mouse.
(https://s23.postimg.org/natvikh9n/Bez_n_zvu.png)