gpt4 book ai didi

python - pygame.error:混合器未初始化如何解决?

转载 作者:行者123 更新时间:2023-12-03 01:17:09 30 4
gpt4 key购买 nike

所以我正在向游戏加载声音,但出现此错误
我正在使用python 3 Windows 10

pygame.error: mixer not initialized


我尝试过推杆,但是当我推杆时
pygame.mixer.init()

当我放pygame.mixer.init()时,出现此错误?我必须导入一些东西吗?
pygame.error: DirectSoundCreate: No audio device found
import pygame
import math

pygame.init()

pygame.mixer.init()


# window
window = pygame.display.set_mode((800,800))
pygame.display.set_caption("new World")
#
# error bloccks
erblock = pygame.image.load("error.png")

# trees images
treo = pygame.image.load("tree.png")

# mountains
mounto = pygame.image.load("mount.png")

# platform images
blocks = pygame.image.load("block.png")

# coins image
heart = pygame.image.load("heart.png")

# heart image
heartingss = pygame.image.load("health.png")



# define the shooting sound for the player ------------------------
shootsound = pygame.mixer.Sound("ss.wav")

# hit enemy sound
hitenemysound = pygame.mixer.Sound("hitenemy.wav")


# sound for jumping
jumpsound = pygame.mixer.Sound("sjump.wav")

# pick up coins sound
coinssound = pygame.mixer.Sound("coinssound.wav")

# shoot sound
shots = pygame.mixer.Sound("shootsound.wav")

# hit the ice sound
icehit = pygame.mixer.Sound("h.wav")

# health power UP
powerup = pygame.mixer.Sound("pw.wav")


# load this sound if the player is dead
death = pygame.mixer.Sound("death.wav")

# walking sound
walk = pygame.mixer.Sound("walks.wav")

# background music
music = pygame.mixer.Sound("backgroundsong.wav")
pygame.mixer.music.play(-1)

最佳答案

我还遇到了类似的错误,如下所示:

pygame.error: WASAPI can't find requested audio endpoint: Element not found.
我意识到,我忘记将耳机插入台式机了,这意味着台式机没有音频输出设备。这导致pygame不知道在哪里输出声音(在您的情况下无法找到音频设备),从而引发错误。
插入音频设备(即我的耳机)后,它就像一个护身符!

关于python - pygame.error:混合器未初始化如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62125225/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com