Jump to content


OpenAL, play sound while key pressed


2 replies to this topic

#1 Gatus

    New Member

  • Members
  • Pip
  • 4 posts

Posted 28 April 2005 - 03:50 AM

Hi, I happily got openAL working after reading the tutorials, however, there's one question that arose and that seems it was left wo. answer.

I have a fps camera and it moves when I press the up arrow key, I've a keydown checker (set to tell me which key is being pressed or released, in my main loop). How can I bind an openAL sound to it, so while it is pressed the sound plays but if released, it pauses?

Thanks.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 28 April 2005 - 05:59 AM

I haven't used OpenAL myself, but I assume it gives you interfaces to stop and start sounds. Then you just need to keep a flag to indicate the state of the key last frame. Each frame, you can check: if the key was up last time, but down this time, start the sound. And if it was down last time but up this time, stop the sound. Then update the flag to hold the current state of the key.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Gatus

    New Member

  • Members
  • Pip
  • 4 posts

Posted 28 April 2005 - 03:56 PM

Thank you, that worked fine :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users