gpt4 book ai didi

python - 需要帮助在我的pygame代码上切换音乐背景

转载 作者:行者123 更新时间:2023-12-03 00:43:57 26 4
gpt4 key购买 nike

图片正在尝试切换背景音乐
触底,当触顶时回到第一个。什么时候
我尝试将其放在while #formula中,然后每次都会重置
它下降了一点,那不是我想要的。
您能帮我弄清楚如何放置此代码:

pygame.mixer.music.load('song1')
pygame.mixer.music.play(-1, 0.0)

pygame.mixer.music.load('song2')
pygame.mixer.music.play(-1, 0.0)

在下面的代码中,并按照我在此处的说明进行切换?
如果我忘了解释你需要知道的事情
请告诉我。
import pygame, sys
from pygame.locals import *

pygame.init()

FPS = 200
fpsClock = pygame.time.Clock()

DISPLAYSURF = pygame.display.set_mode((400, 400), 0, 0)
pygame.display.set_caption('Verkefni 21')

WHITE = (255, 255, 255)
clownx = 10
clowny = 10
direction = 'right'
stefna = 'niður'

while True:
DISPLAYSURF.fill(WHITE)
if stefna == 'niður':
if direction == 'right':
clownImg = pygame.image.load('sarah.jpg')
clownx += 5
if clownx == 320:
clowny += 10
direction = 'left'
clownImg = pygame.image.load('john.jpg')
if clowny == 300:
stefna = 'up'
soundObj = pygame.mixer.Sound('bomb.wav')
soundObj.play()
import time
time.sleep(2) # wait and let the sound play for 1 second
soundObj.stop()

elif direction == 'left':
clownImg = pygame.image.load('john.jpg')
clownx -= 5
if clownx == 10:
clowny += 10
direction = 'right'
clownImg = pygame.image.load('sarah.jpg')
if clowny == 300:
stefna = 'up'
soundObj = pygame.mixer.Sound('bomb.wav')
soundObj.play()
import time
time.sleep(2) # wait and let the sound play for 1 second
soundObj.stop()
elif stefna == 'up':
if direction == 'right':
clownImg = pygame.image.load('arnold.jpg')
clownx += 5
if clownx == 320:
clowny -= 10
direction = 'left'
clownImg = pygame.image.load('terminator.jpg')
if clowny == 0:
stefna = 'niður'
soundObj = pygame.mixer.Sound('bomb.wav')
soundObj.play()
import time
time.sleep(2) # wait and let the sound play for 1 second
soundObj.stop()
elif direction == 'left':
clownImg = pygame.image.load('terminator.jpg')
clownx -= 5
if clownx == 0:
clowny -=10
direction = 'right'
clownImg = pygame.image.load('arnold.jpg')
if clowny == 0:
stefna = 'niður'
soundObj = pygame.mixer.Sound('bomb.wav')
soundObj.play()
import time
time.sleep(2) # wait and let the sound play for 1 second
soundObj.stop()

DISPLAYSURF.blit(clownImg, (clownx, clowny))

for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()

pygame.display.update()
fpsClock.tick(FPS)

最佳答案

切换歌曲时,请输入pygame.mixer.music.stop()

关于python - 需要帮助在我的pygame代码上切换音乐背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29677335/

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