SFML community forums
Help => Window => Topic started by: sandwich hoop on July 04, 2024, 05:03:16 pm
-
Hi,
When I have two instances of my game open, and try to press A to move left (which does work) both instances of the game accept the A input. My question is, is there any way to create a window which won't overlap with other instances so that if I press A in one, it doesn't impact the other? Hope that makes sense, I can clarify things if needed, hopefully, I'm just overlooking something simple.
Edit: I can't just run it on another computer because what I'm testing is the network connection, but I want to get everything else working before I figure out how to do it between computers.
:)
-
If you use events, then only the window with the focus will get the input.
That means, don't use sf::Keyboard::isKeyPressed() or sf::Mouse::getPosition() or sf::Mouse::isButtonPressed().
Check the official tutorial on events: https://www.sfml-dev.org/tutorials/2.6/window-events.php
-
Or as an alternative you could put the code in an if statement checking window.hasFocus().
-
Exactly what I was looking for! Thanks! This is such a useful little feature I wish I knew about sooner!
:)