【发布时间】:2018-01-16 16:57:34
【问题描述】:
我刚刚在我的 pygame 游戏中添加了一些音乐,但我认为代码非常混乱,以至于没有任何东西在正确的位置。由于此添加,我现在收到此错误:
Traceback(最近一次调用最后一次):文件 “C:\Users\1234\AppData\Local\Programs\Python\Python36-32\我的第一个游戏 ERROR.py”,第 31 行,在 对于 pygame.event.get() 中的事件:pygame.error: 视频系统未初始化
这是我写的代码:
import pygame, sys
pygame.mixer.init(44100, -16,2,2048)
class Game(object):
def main(self, screen):
import time
pygame.mixer.music.load('The Tonight Show Star Wars The Bee Gees Stayin Alive Shortened.mp3')
pygame.mixer.music.play(-1, 0.0)
#class Player(pygame.sprite.Sprite):
# def __init__(self, *groups):
# super(Player, self.__init__(*groups)
#self.image = pygame.image.load('Sprite-01.png')
# self.rect = pygame.rect.Rect((320, 240), self.image.get_size())
#def update(self):
# key = pygame
image = pygame.image.load('Sprite-01.png')
clock = pygame.time.Clock()
# initialize variables
image_x = 0
image_y = 0
while 1:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.quit():
pygame.quit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
pygame.quit()
image_x += 0
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
image_x -= 10
if key[pygame.K_RIGHT]:
image_x += 10
if key[pygame.K_UP]:
image_y -= 10
if key[pygame.K_DOWN]:
image_y += 10
screen.fill((200, 200, 200))
screen.blit(image, (image_x, image_y))
pygame.display.flip()
pygame.mixer.music.stop(52)
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('St.Patrick game')
Game().main(screen)
【问题讨论】:
-
请正确缩进您的代码,以便我们可以准确地看到您在编辑器中看到的内容。单击编辑,粘贴您的代码,全选并按 Ctrl+K 或
{}按钮以正确格式化。 -
对不起,我只是手动添加了四个空格。
-
暂时将您的代码发布在pastebin.com 或gist.github.com 上,以便我们查看您的程序的实际外观(我们可以为您添加到帖子中)。