2

我想知道是否有人可以帮助我使用 pygame(Python)。我不断从我的代码中收到错误:

bif ="bg.jpg"
mif = "mouse.png"
import pygame
import sys

from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((682,415),0,32)
backround= pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert()
x, y =0,0
movex, movey =0,0
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.tpye == KEYDOWN:
            if event.key==K_LEFT:
                movex =-1
            elif event.key==K_RIGHT:
                movex=+1
            elif event.key ==K_UP:
                movey=-1
            elif event.key==K_DOWN:
                movey=+1

我得到的错误是:

Traceback (most recent call last):
  File "C:\Documents and Settings\Aidan\Desktop\Mygame.py", line 15, in <module>
    screen=pygame.display.set_mode((682,415),0,32)
pygame.error: No available video device`

我有一台在 Windows XP 上运行的 Sony Vaio VGN-T1XP。

4

2 回答 2

0

对我来说,这听起来像是一个深度问题……来自 PyGame 文档:

“通常最好不要传递深度参数。它将默认为系统的最佳和最快颜色深度。如果您的游戏需要特定的颜色格式,您可以使用此参数控制深度。Pygame 将模拟不可用的颜色深度这可能很慢。”

你在这里找到它:http: //www.pygame.org/docs/ref/display.html#pygame.display.set_mode

所以最好的解决方案是只保留默认的标志和深度。到目前为止,我总是这样使用它。从我的一些旧代码:

SCREEN = pygame.display.set_mode((1024, 768))

试试这种方式,让我们知道它是否有效。并且在 PyGame 上玩得更开心,我真的开始喜欢它了 :D 如果你需要更多好的教程,请随时问我 :)

于 2014-04-17T15:08:31.537 回答
0

您到那里的硬件/软件似乎是过时的问题。您可以尝试使用 pygame 提交问题,或者尝试自己调试 pygame 以找出原因,但这会很复杂。我真的无法复制它,甚至尝试使用我的 windows XP virtualbox。

于 2013-05-03T15:23:51.347 回答