SFML community forums
Help => Window => Topic started by: L1NTHALO on February 23, 2024, 09:54:07 pm
-
Hey everyone, I'm new to SFML and programming... somewhat? Currently trying to code the retro ping pong game and I'm having a problem with keyboard input and player movement.
I can't press two keys at the same time. I'm checking for a KeyPressed event and then for the keycode. That of course leads to a maximum of one switch statement snippet being run at the same time. I heard that the event system is a poor way of implementing player movement but the only alternative (sf::Input) seems to be deprecated.
I can't really come up with a solution. Could you help me out? I would appreciate a hint (only a hint so I can solve the rest myself) into the right direction because I never implemented player movement at such a "low" level.
-
Events are a great way to implement movement, but you might need to store some states, so you can check multiple keys at the same time.
Meaning, store the state of a key, whether it's pressed (true) or released (false). Then outside the event loop you can check the state of multiple keys at the same time.
SFML 1.6's sf::Input was replaced by sf::Keyboard / sf::Mouse / sf::Joystick, but events are superior and work the best across platforms.