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

Author Topic: Sound playing the moment the key is pressed  (Read 3699 times)

0 Members and 1 Guest are viewing this topic.

Ranzini

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sound playing the moment the key is pressed
« on: March 13, 2023, 02:14:22 pm »
So i want a Sound to play, the moment the button is pressed.
With:

 if (Keyboard::isKeyPressed(Keyboard::Space))

the sound playes the moment i let go of the button.
Thanks in advance

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Sound playing the moment the key is pressed
« Reply #1 on: March 13, 2023, 11:44:27 pm »
...restarts it from beginning if it was it already playing
Don't call play() if it's already playing, you won't hear anything if you restart the sound every frame.

May want to use an event like the KeyPressed Event instead.