Pygame-同时播放声音 [英] Pygame - Play sounds simultaneously

查看:155
本文介绍了Pygame-同时播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pygame制作游戏,我想做的是在每个关卡都有一个主声音,并在收集分数时听到一些默认声音(例如)

I am making a Game using Pygame and what I'm trying to do is to have a main sound for every level and some default sounds being heard when collecting points (e.g.)

因此,我使用以下命令加载主级音乐:

So, I load the main level music using:

pygame.mixer.music.load(music_file)
pygame.mixer.music.play(-1)

现在,我想做的就是每当玩家收集一个点时播放特定的声音.我无法使用以下音乐来停止音乐:

Now, what I want to do is to play a specific sound whenever a player collects a point. I cannot stop the music using:

pygame.mixer.music.stop()
pygame.mixer.music.load(point_music)
pygame.mixer.music.play()

因为关卡的音乐将停止播放.

because the level's music will stop playing.

所以,我尝试做这样的事情:

So, I've tried doing something like this:

points_sound = pygame.mixer.Sound("point.mp3")
points_sound.play()

我知道pygame中播放的声音是在自己的线程上运行的,但是我确定程序/游戏不会在结束播放声音之前终止.

I know that sound playing in pygame runs on its own thread but I am sure that the program/game does not terminate prior to finish playing the sound.

长话短说:玩家可以收集积分,但是我无法让pygame播放收集积分的声音.

Long story short: The player can collect points but I am unable to make pygame play the collecting points sound.

推荐答案

sr2222 在评论中说:

医生说,对音乐的mp3支持是有限的,只有OGG和WAV 支持声音.您是否尝试过以下一种格式 官方支持吗?

Docs say mp3 support is limited for music and that only OGG and WAV are supported for Sound. Have you tried one of the formats that are officially supported?

尝试为您的声音尝试OGG或WAV格式,这应该可以.

Try out OGG or WAV formats for your sounds instead, that should work.

这篇关于Pygame-同时播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆