【发布时间】:2016-05-06 15:12:21
【问题描述】:
我正在尝试制作一个平台游戏,并且在下面的代码中,我尝试在背景上移动一个图像('bird.png')。但是,每次我尝试启动 pygame 时它都会崩溃,甚至没有加载任何图像。我检查了其他页面,但仍然没有解决问题。代码中可能有一些错误,但我无法检查它是否正常工作,因为正如我所说,pygame 不断崩溃。有什么办法可以解决吗?
PS。对不起,如果它有点乱,代码中的法语单词:)
import pygame
from pygame import *
pygame.init()
TE=[]
def perso(X):
X = [0,448]
while X != [640,0]:
w=int(input("Déplacement: "))
#Right#
if w==0:
if X[1] == 608:
print("You can't leave the map")
else:
X[1] += 32
print(X)
#Left#
elif w==1:
if X[1] == 0:
print("You can't leave the map")
else:
X[1] -= 32
print(X)
#Down#
elif w==2:
if X[0] == 456:
print("You can't leave the map")
else:
X[0] += 24
print(X)
#Up#
elif w==3:
if X[0] == 0:
print("You can't leave the map")
else:
X[0] -= 24
print(X)
else:
print("non valable")
print("Bravo!")
screen = pygame.display.set_mode((680, 488)) background_image = pygame.image.load("C:/Python34/Scripts/Images & Sounds/background(680x480).jpg").convert()
screen.blit(background_image,[0,0])
character = pygame.image.load("C:/Python34/Scripts/Images & Sounds/bird(40x40).png").convert()
screen.blit(character, (X[0],X[1]))
perso(TE)
flag
我运行代码,当 pygame 窗口打开时,它是黑色的,几秒钟后我收到“无响应”消息(对于 pygame 窗口)。但是,w=int(input("Déplacement: ")) 部分似乎在要求输入时起作用。也许这与图像有关?
【问题讨论】:
-
崩溃是什么意思——需要给出你遇到的具体异常代码
-
我运行代码,当 pygame 窗口打开时,它是黑色的,几秒钟后我收到“无响应”消息(对于 pygame 窗口)。但是,“w=int(input("Déplacement: "))" 部分似乎在要求输入时起作用。也许这与图像有关?
-
您有一个可能未满足条件的 while 循环。我怀疑。添加 而不是 640 的东西和 cntr 。然后在正文中添加 cntr +=1 并在循环之前添加 **cntr = 0 **。
-
Id 还在置换提示之前放置了一个打印。并摆脱口音,以防它对非英语字符感到厌烦。
-
您也可以尝试将文件复制到 c:\temp\nofunnychars.png 并以这种方式引用它,在 windows 技巧上使用奇怪的“/”