简体   繁体   中英

C++ SFML mouse movement

I'm trying to detect mouse movement event and move it back to the middle of the screen using sf::RenderWindow pollEvent method and detect the event type sf::Event::MousePressed. The problem is when I'm detecing the mouse movment I need to move the mouse back to the middle of the screen and for that im using sf::Mouse::setPosition but I think (maybe I'm wrong) that function itself calling sf::Event::MouseMoved when it used, and im afraid it creates an infinite loop.

Exmaple of the way im doing that: (I know 0, 0 it's not the middle it is just and exmaple)

while (app.pollEvent(Event))
{
  if(Event.type == sf::Event::MouseMoved)
        {
            sf::Mouse::setPosition(0 , 0));
        }
}

Sorry for my bad english! Thanks in advance!

Try using app.SetCursorPosition(x, y); instead.

Also, i would skip the check for events, since you will want the cursor to end in the middle at the end of each frame anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM