Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to change volume of sounds in Pygame Zero?

I’m working on fully fleshing out a game I made following a tutorial, and have been trying to incorporate sound effects into the finished thing. However they are way too loud and I can’t seem to find a way to quieten them. I know there’s a way in normal pygame but I don’t know if there’s one for pgzero. Any help would be greatly appreciated 🙂

Here’s a snippet of code in case that helps:

if gem.colliderect(ship):
        sounds.gem_collect.play()
        gem.x = random.randint(20, 1180)
        gem.y = 0
        score = score + 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I have never used pygame zero. But here is the documentation. Doesn’t say anything about setting volume for sound objects, but you can set_volume() for music:

music.set_volume(volume)

Set the volume of the music system.
This takes a number between 0 (meaning silent) and 1 (meaning full volume).

You could try to use the set_volume() method on a sound object and see what happens. Maybe it’s just not documented well.

if gem.colliderect(ship):
    sounds.gem_collect.set_volume(0.2)
    sounds.gem_collect.play()
    gem.x = random.randint(20, 1180)
    gem.y = 0
    score = score + 1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading