python - pygame.mixer.music,只要 while 循环正在运行,我就想播放曲目
问题描述
import pygame
import sys
import time
from pygame.locals import *
pygame.init()
pygame.mixer.pre_init(44100, 16, 2, 4096)
#music files variables
eatsound = ("E:\p\code\eat.mp3")
gameoversound = ("E:\p\code\gameovertrimmed.mp3")
main = ('E:\p\code\mainm.mp3')
playsurface = pygame.display.set_mode((720, 480))
pygame.display.set_caption('Snake Game!')
fpscontroller = pygame.time.Clock()
while True:
pygame.mixer.music.load(main)
pygame.mixer.music.play(-1, 0.0)
我想让音轨作为背景声音播放,直到循环结束。但是,while 循环不允许它这样做
解决方案
一旦
pygame.mixer.music.play(-1, 0.0)
方法被调用,不需要在你的while循环中一遍又一遍地调用它
初始化循环时调用它一次,然后在 while 循环退出时停止它
推荐阅读
- nginx - nginx 从不同的位置指令发送标头
- tensorflow - 训练图像?选择注意事项
- python - 这种 python 索引:'print(X_train[y_train == 0][0])' 如何在 python 中工作?
- php - 使用未定义的常量标题 - 假定为“标题”
- docker - 如何从 hyper-v 虚拟机连接到 windows docker 容器的公开端口?
- python - 节点错误在远程服务器上生成 /bin/sh ENOENT
- javascript - 在spring mvc视图上实现UI-GRID angular
- django - 如何对 Django FloatField/DecimalField 进行比较操作
- javascript - Javascript查找两个数组缺失元素的索引
- google-chrome - Chrome 和 HTML5 离线存储