Pygame搅拌机声音叠加
当按下箭头键时,我正在尝试使用混音器来播放脚步。但是,每当我这样做时,显然都会不断检测到按钮并不断覆盖声音。
def walking():
walk = pygame.mixer.Channel(2)
walk_sound = mixer.Sound("Music/Walking.mp3")
walk.play(walk_sound)
if walk.get_busy():
# Don't play anything
这是步行声的功能。如果有声音播放,有没有办法不玩任何东西?
if keypress[K_RIGHT]:
self.rect.move_ip(x, 0)
self.image = walk_right[walk_count // frame_count]
display.blit(self.image, (self.rect.x, self.rect.y))
walk_count += 1
self.last = "right"
walking()
这是我的播放器课程的一部分,也是移动方法,以显示我称之为步行声功能的位置。
I'm trying to use mixer to play footsteps when the arrow keys are pressed. But whenever I do it obviously keeps detecting the button and continuously overlays the sound.
def walking():
walk = pygame.mixer.Channel(2)
walk_sound = mixer.Sound("Music/Walking.mp3")
walk.play(walk_sound)
if walk.get_busy():
# Don't play anything
This is the function for the walking sound. Is there a way to not play anything if there is a sound playing?
if keypress[K_RIGHT]:
self.rect.move_ip(x, 0)
self.image = walk_right[walk_count // frame_count]
display.blit(self.image, (self.rect.x, self.rect.y))
walk_count += 1
self.last = "right"
walking()
This is part of my Player class and Move method to show where I call the walking sound function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建通道并在初始化时循环循环之前加载声音。只需在
Walling
函数中启动声音,如果频道不是忙>
:Create the channel and load the sound before the application loop at initialisation. Just start the sound in the
walking
function if the channel is notbusy
: