[SOLVED]Sound Effect Continuously Playing

Hello forum, I am having an issue with a sound effect. It is a short punch sound, and I am simply trying to have it play when  one actor punches another. However, instead of playing the sound once, it just loops it and makes a machine gun sound. In the code it is set to play, not loop. So what is the issue, how can I make it just play once on contact?

« Last Edit: March 09, 2017, 07:29:46 pm by CaptainBearFace11 »

LIBERADO

  • *
  • Posts: 2720
Surely you are continuously running the "play" block, so you are continuously playing the sound.
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

The play sound code is set to go off as a result of a collision.  So what's happening is that as long as the collision is occurring, the sound is playing. How do I remedy this, where should I put the sound code?

decafpanda

  • Posts: 206
Couple of things could be going on.

1:  Is the sound playing in an updating or always event? This will trigger the sound every frame and give that machine gun effect

2:  do you have health implemented in your game or do things die in one hit?  If you have not implemented a health system yet and the enemies do not die (but collisions are still registered) what is happening is that Stencyl is registering that collision not just once but a bunch of times while the punch is occurring.  So the sound is playing a bunch of times.

This is solved by a simple boolean that I could walk you through and might even be the first steps in implementing a health system.

A quick fix would be to make the enemies die on collision with the punch thus the sound will only play once because only one collision will take place






The sound is not in an always or updating event, it is in Type and Type collision event. It sounds like the second situation- there is no health system and the enemies do not die in one hit. I would much appreciate a walk through on how to solve this

merrak

  • *
  • Posts: 2738
I built a standard SFX manager behavior to handle this sort of thing. It's simple to put together. Make a custom block "play sound (SFX) once". The code should add the sound to a list and remove it after a short delay (you can also make this delay a second argument). If the sound is in the list, don't play it. Otherwise, play it and add it to the list.

decafpanda

  • Posts: 206
Hey I am bored tonight and I figured I would make a video to help you with your problem.

 Merrak's behavior most certainly will work for you but you might find watching this video to be informative on booleans and other beginner techniques for gamedev. 

I am very new to stencyle too so I have had a lot of the same problems you have.  This is how I fixed the issue you are having.

https://www.youtube.com/watch?v=KW-nF5_fb8M

Thank you to Merrak and Decafpanda for the help. Decafpanda, that was an incredibly helpful tutorial. Makes total sense, problem solved. Thanks a bunch

decafpanda

  • Posts: 206
No problem, glad to help!

Extintor

  • Posts: 5
Decafpanda, so many thanks. At least!