나는 파이썬 3, 파이 게임으로 작성된 게임을하고있다. 플레이어가 S를 눌러 게임 진행 상황 (장면과 음악)을 일시 중지하고 계속하려면 다시 누를 수있는 기능을 소개하고자합니다.은 pygame.mixer.music입니다. 내 방식으로 작동해야합니까?
하지만 pygame.mixer.music.pause()가 작동하지 않고 pygame.mixer.music.get_busy()가 항상 True라는 것을 알았습니다.
stop() 작동하지만 음악이 일시 중지 된 곳부터 계속할 수 있도록 pause()가 필요합니다. 다음은
내가 문제의 가능한 범위를 좁힐 쓴 프로그램입니다 : 마지막으로import pygame
import random,sys
from pygame.locals import *
''''conclusion: pause() is not working(seems it triggers nothing, and
as a result, get_busy() is not working with pause())
'''
# Define some colors
black = ( 0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
blue = ( 0, 0, 255)
purple = (159, 0, 197)
bgColor= (0, 0, 0)
textColor = (250, 250, 255)
width = 600
height = 600
def end():
pygame.quit()
sys.exit()
def drawText(text, font, surface, x, y):
textobj = font.render(text, 1, textColor)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
pygame.init()
screen = pygame.display.set_mode([width,height])
pygame.mixer.music.load('background.mid')
font = pygame.font.SysFont(None, 48)
clock = pygame.time.Clock()
pygame.mixer.music.play(-1, 0.0)
pygame.mixer.music.set_volume(0.5)
paused=False
while True: #game loop when the game is playing.
if not pygame.mixer.music.get_busy(): #is not playing
print("Not playing")
for event in pygame.event.get():
if event.type == pygame.QUIT:
end();
elif event.type == KEYUP:
if event.key == K_ESCAPE:
end()
elif event.key == K_s:
print("pause.")
#pygame.mixer.music.pause()
pygame.mixer.music.stop()
screen.fill(bgColor)
pygame.display.flip()
clock.tick(40)
왜'False'를 반환하려면'get_busy()'가 필요합니까? ''일시 중지하지 않았다면 :'을 사용하고'K_s'를 설정/해제 할 수 있습니다. 'pygame.mixer.music.pause()'를 호출하면 음악이 일시 정지됩니까? – jfs
여기서 문제는 pause()가 아무 것도하지 않는다는 것입니다. 음악은 여전히 재생됩니다. 파이 게임 문서에 따르면 get_busy()는 음악이 재생 중일 때 True를 반환합니다. – Peihui
그래서 'music.pause()'는 음악을 일시 중지하지 않습니다. 'get_pos, stop'을 사용하여 에뮬레이션하려고 시도 했습니까? 일시 중지하고'set_pos, play' 명령으로 일시 중지 하시겠습니까? – jfs