如何在 PyGame 中更改声音或音乐的音量? [英] How do I change the volume of the sound or music in PyGame?
本文介绍了如何在 PyGame 中更改声音或音乐的音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 PyGame 中更改音量,例如通过转到设置来更改音量.我做了UI元素,只需要知道如何改变音量.我知道我不清楚,但你可以理解我.请帮忙
How to change volume in PyGame like changing the volume by going to the settings. I made the UI elements, just need to know how to change the volume. I know I am not clear, but you can understand me. Please help
推荐答案
改变音量取决于你是否在玩 pygame.mixer.Sound
对象或通过 pygame.mixer.music
模块.
Changing the volume depends on whether you are playing a pygame.mixer.Sound
object or playing the music via the pygame.mixer.music
module.
声音的音量可以通过set_volume()
.体积参数是范围 [0.0, 1.0] 中的值:
The volume of a Sound can be changed by set_volume()
. The volume argument is a value in range [0.0, 1.0]:
pygame.mixer.init()
my_sound = pygame.mixer.Sound('my_sound.wav')
my_sound.play()
my_sound.set_volume(0.5)
可以通过更改音乐的音量pygame.mixer.music.set_volume()
:
pygame.mixer.init()
pygame.mixer.music.load('my_music.mp3')
pygame.mixer.music.play()
pygame.mixer.music.set_volume(0.5)
这篇关于如何在 PyGame 中更改声音或音乐的音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文