Acabo de comenzar un pequeño proyecto de juego e bash hacer que se reproduzca un sonido cada vez que se dispara una bala, pero sigo recibiendo el mismo error:
pygame.error: sistema mezclador no inicializado
No entiendo lo que hago mal, aquí está mi código:
import pygame, sys from pygame.locals import * theClock = pygame.time.Clock() sound = pygame.mixer.Sound("bullet.mp3")
….
if event.type == KEYDOWN: if event.key == K_SPACE and shot_count == 0: sound.play() shot_y = h-50 shot_x = x elif event.type == K_SPACE and shot_count == 1: shot_y_2 = h-50 shot_x_2 = x print(h, ' ', shot_y, shot_count) if event.type == KEYUP: if event.key == K_SPACE and shot_count == 0: resetShot = 0 elif event.type == K_SPACE and shot_count == 1: resetShot = 0
Necesitas pygame.init()
antes de usar objetos de sonido / mezclador.
Según la documentación , debe utilizar archivos de sonido OGG o WAV.
¡Estaba haciendo un juego de Tetris antes de dos semanas y tuve el mismo problema! Lo que hice fue insertar esto antes de reproducir el sonido y funcionó.
pygame.mixer.init(44100, -16,2,2048)
¡Pruébalo tú mismo y ve si funciona! Espero que haya ayudado