Log In  
Log In  

At the moment I am trying to make a sound play once during a collision.

The collision doesn't stop player speed, but rather the player can "run" through the collision box.
This means that the collision function returns true for several frames in the game.

Whilst can get a collision to play a sound, because the function is returning true for several frames the sound bite keeps restarting every frame.

Could someone please explain how I could make it so that

Whilst collision = True
Sfx plays all the way through(only once though)

I am currently trial and erroring my way through this, but I wondered if I could cut that a little shorter by asking a question on here. I did try searching online for tutorials regarding this but they either make a sound effect play when a button is pressed, or something that doesn't necessarily apply to a situation like this.

Thanks.

P#64448 2019-05-16 02:52

flip a variable ‘colliding’ when entering collision state, flip it back to false when exiting.
fire the sound only in case of collision and ‘colliding’ is false (eg a new collision).

P#64452 2019-05-16 07:09

@freds72 thanks alot for your quick response, it works!.

Sorry for the late reply by the way.

P#64565 2019-05-18 18:47

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-05-24 18:55 | 0.018s | 2097k | Q:14