This site requires JavaScript, please enable it in your browser!
Greenfoot back
Reaper47
Reaper47 wrote ...

2016/6/21

Need help with setting up footstep audio for WASD movement.

Reaper47 Reaper47

2016/6/21

#
I want it to where an audio (audio of footsteps) will play and loop while W,A,S or D is being held down, and I need the audio to stop after the keys are not being held down. Thing is I also need it to where if I were to hold down 2 or more keys at a time that it doesn't play more than one audio. I currently have no coding to even attempt this due to my lack of knowledge on where to even begin. If someone could give me a rough draft or idea of what I need to do that would be great!
danpost danpost

2016/6/21

#
First, you need a local int variable to count the keys that are down. If the result is one, ensure that the sound is playing; if not, ensure that no sound is playing. Keep a reference field for the GreenfootSound object for the footsteps sound so you can have that object be the one that you play and you can check its playing state easily.
Reaper47 Reaper47

2016/6/21

#
Okay, that makes sense. I think I can do that, thank you.
You need to login to post a reply.