Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: how to go about player movement?  (Read 2751 times)

0 Members and 1 Guest are viewing this topic.

L1NTHALO

  • Newbie
  • *
  • Posts: 3
    • View Profile
how to go about player movement?
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: how to go about player movement?
« Reply #1 on: February 25, 2024, 01:12:38 pm »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything