0

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

2 Answers2

0

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
0

In Pygame zero's documentation I didn't found a way to control volume using sounds but you can change it in Music.

if gem.colliderect(ship):
        music.play_once(track_name) # you don't need to add track extenstion in it
        music.set_volume(num) # num is any number between 0 (meaning silent) and 1 (meaning full volume)
        gem.x = random.randint(20, 1180)
        gem.y = 0
        score = score + 1

Attention This Music api is experimental and have it's own drawbacks and is only availbale in 1.1 and after. Some of the Drawbacks

  • MP3 may not be available on some Linux distributions.

  • Some OGG Vorbis files seem to hang Pygame with 100% CPU.

more about Music in pygame zero link