2011-05-14 4 views
6

지금은 작동하고 있지만 시간 지연으로 인해 더 좋은 방법이 있습니다. 왜냐하면 두 개의 다른 스크립트가 작동하기를 원하기 때문입니다.이 순서대로 재생해야하며 이미지가 순서대로 나타나고 이미지가 긴 스크립트와 시간 지연도 있습니다.파이 게임에서 하나 이상의 노래를 재생할 수 있다면 어떨까요?

#!/usr/bin/env python 
import pygame 
pygame.mixer.init() 
pygame.mixer.pre_init(44100, -16, 2, 2048) 
pygame.init() 
print "hey I finaly got this working!" 
sounda= pygame.mixer.Sound('D:/Users/John/Music/Music/FUN.OGG') 
soundb= pygame.mixer.Sound('D:/Users/John/Music/Music/Still Alive.OGG') 
soundc= pygame.mixer.Sound('D:/Users/John/Music/Music/turret.OGG') 
soundd= pygame.mixer.Sound('D:/Users/John/Music/Music/portalend.OGG') 
sounda.play() 
pygame.time.delay(11000) 
soundb.play()<P> 
pygame.time.delay(180000) 
soundc.play() 
pygame.time.delay(90000) 
soundd.play() 

답변

7

pygame.Mixer 모듈을 확인 했습니까? 기본적으로 8 곡을 동시에 재생할 수 있습니다.

pygame.mixer.music을 사용하면 한 번에 하나의 노래 만 재생할 수 있습니다.

pygame.mixer.sound을 사용하면 그 당시 최대 8 곡을 재생할 수 있습니다.

music module은 음악을 스트리밍하기 위해 여기에 있습니다 (한번에 모든 음악 파일을로드하지는 않습니다).

sound module은 게임 중에 다른 사운드를 재생하기 위해 여기에 있습니다 (사운드가 메모리에 완전히로드 됨).

따라서, 귀하의 예제에서 당신은 같은 시간에 4 곡을 재생하려면 :

import pygame 
pygame.mixer.init() 
pygame.mixer.pre_init(44100, -16, 2, 2048) 
pygame.init() 
print "hey I finaly got this working!" 
sounds = [] 
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/FUN.OGG')) 
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/Still Alive.OGG')) 
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/turret.OGG')) 
sounds.append(pygame.mixer.Sound('D:/Users/John/Music/Music/portalend.OGG')) 
for sound in sounds: 
    sound.play() 
+0

네, 그렇지만 채널을 어떻게 사용합니까? 채널을 어떻게 지정합니까? – user754010

+0

@user : 내 대답 편집 –

0

다음 스크립트 (sound_3.wav하는 sound_0.wav) 4 사운드를로드하고 재생합니다.

sounds = [] 
for i in range(4): 
    sound = pygame.mixer.Sound('sound_%d.wav'%i) 
    sound.play() 
    sounds.append(sound) 
관련 문제