Sound in games distorts


#1

A team is adding music to their game. It sounds fine when they place the sound OUTSIDE the draw loop. It is super distorted to the point of static if they place it INSIDE the draw loop. They need it inside the loop to control when it plays. We can’t figure out why it’s distorted. Any ideas?


#2

Figured it out! Well, this works:

function draw() {
playSound(“crab.mp3”, false);
stopSound(“crab.mp3”);

They hadn’t stopped the sound. Adding that line of code makes it not distort inside the draw loop.


#3

Susan,

Great problem solving!

Brad


#4

I’m throwing this back out there for more feedback. This solution doesn’t work consistently? Any ideas what we are doing incorrectly?


#5

@sdiaz

Hi Susan,

I think the main problem is that the sound is restarting every time you run the draw loop, which is causing distortion. It’s really hard to know without a link to the actual project, though. Can you click the “Share” button and paste the link here so other people try to help?

Thanks,
Elizabeth