help with sound overlap

T

temmieflakes42

Guest
before you get mad at me: yes ive looked this up, i tried everything i could find, nothing worked
ive got a sound set to play only once when i press the up arrow key, and stop playing when it is released
however, i want the sound to not play again until the player hits the ground and executes another jump
currently, the player can press up as much as they want while in the air and continuously play the sound
i used the drag and drop functions because i could not figure out how to do it in code.
i used a keyboard press event and keyboard release event
the keyboard press plays the sound once, the keyboard release stops the sound
this is my first day using gamemaker and ive been working hard for the past 14 hours and i just need help with this one little thing because no google results ive found are helping
thank you in advance!
 
A

Aura

Guest
Have you come across audio_is_playing() and the not (!) operator yet?

Code:
if (!audio_is_playing(snd_jump))
{
   // Play the sound
}
The above code plays the sound if an instance of snd_jump is not being played already. Hope that helps.
 
T

temmieflakes42

Guest
i tried it and it doesn't work, it still produces the same effect
i dont know if i'm putting it in the wrong place or what but,
my sound is named "sound0" and i put the code into the Step event for my "obj_player"

Code:
if (!audio_is_playing(sound0))
{
   sound_play(sound0)
}
 
S

SoulTie

Guest
Use audio_play_sound() instead of sound_play. Hopefully that fixes the issue.
 
T

temmieflakes42

Guest
nnnnope, this just causes a new glitch where the jump sound plays on repeat over and over from the start of the level and does not stop at any point
 
A

Aura

Guest
Don't use sound_play() if you are using GM:S. Use audio_play_sound() instead.

And you need to play the sound while jumping, that is, when the jump key is detected. Just wrap the audio_play_sound() call in the audio_is_playing() check.
 

johnwo

Member
Don't mix sound_* and audio_* functions.
They are separate; Old and new audio engine respectively.

Cheers!
 
T

temmieflakes42

Guest
the problem has been solved thanks to SoulTie
thank you very much for your help!
 

shocwav

Member
Just wanted to let y'all know this was very helpful even 7 years later. I had a game over jingle that was overplaying itself and driving me nuts.
 
Top