无法将音乐加载到 pygame 中 [英] Can't load music into pygame

查看:67
本文介绍了无法将音乐加载到 pygame 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以,请帮忙.似乎无法将音乐上传到我正在进行的游戏中.它出现了无法加载"的错误...如果有人能尽快回复我,那就太好了,这是 1 周后到期的主要工作

please help if you can. Can't seem to be able to upload music into my game in progress. It comes up with the error of "can't load"... Would be great if someone got back to me quick, This is a major work due in 1 week

import sys, random, pygame, time
from pygame.locals import *
pygame.init()

screen = pygame.display.set_mode((600,500))
pygame.display.set_caption("game")
myfont = pygame.font.SysFont("cambria", 19)
myfont2 = pygame.font.SysFont("cambria", 45)
myfont3 = pygame.font.SysFont("cambria", 30)

#music

pygame.mixer.music.load('sddmusic.mp3')
pygame.mixer.music.play(0)



def print_text(font, x, y, text, color):
    imgText = font.render(text, True, color)
    screen.blit(imgText, (x,y))

game = False
white = 255,255,255

mouse_down_x = mouse_down_y = 0
mouse_down = 0
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == MOUSEBUTTONDOWN:
            mouse_down = event.button
            mouse_down_x, mouse_down_y = event.pos

    screen.fill((85,107,47))

    #print_text(myfont,0,0, str(mouse_down), white)
    #print_text(myfont,0,15, str(mouse_down_x), white)
    #print_text(myfont,0,30, str(mouse_down_y), white) 

    if game == True:
        pygame.draw.line(screen, white, (100,0), (100,600), 20)
        pygame.draw.line(screen, white, (500,0), (500,600), 20)
        time_get = time.clock() - time_start


        if time_get > 1:
           print_text(myfont, 240,0 ,"Hello?", (255,255,255))
        if time_get > 1.75:
            print_text(myfont, 240,50, "Commander?", (255,255,255))
        if time_get > 2.2:
            print_text(myfont, 240,100, "Do you copy?",(255,255,255))

    else:
        pygame.draw.rect(screen, white,(204,176,200,40),2)
        print_text(myfont2, 100, 100,"Operation L.A.U.N.C.H", (255,255,255))
        print_text(myfont3,270,176, "Start", white)
        pygame.draw.rect(screen, white,(204,280,200,40),2)
        print_text(myfont3,270,280, "Quit", white)

        if mouse_down == 1 and mouse_down_x > 204 and mouse_down_y > 176 and mouse_down_x < 404 and mouse_down_y < 216:
            game = True
            mouse_down = 0
            mouse_down_x = 0
            mouse_down_y = 0
            time_start = time.clock()


        if mouse_down == 1 and mouse_down_x > 204 and mouse_down_y > 280 and mouse_down_x < 404 and mouse_down_y < 320:
            pygame.quit()
            sys.exit()




    pygame.display.update()

推荐答案

我猜你的问题是由于以下原因:
1) 转到文件 > 另存为(快捷键:Ctrl+Shift+S)并尝试将 python 文件保存在存储音乐的同一地址中.

I guess your problem is due to the following reason:
1)Go go to file > save as (shortcut : Ctrl+Shift+S) and try saving the python file in the same address in which your music is stored.

建议:
尝试将 mp3 转换为 wav.效果更好.

Suggestion:
Try converting the mp3 to wav.It works better.

这篇关于无法将音乐加载到 pygame 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆