我试着用PyGame做一个简单的迷宫游戏作为初学者的项目,但是当我试着使用event.type时,它说,
Traceback (most recent call last):
File "simple_maze.py", line 22, in <module>
if event.type == pygame.KEYDOWN:
NameError: name 'event' is not defined 作为参考,这是我当前的代码。
import pygame
screendim = (500, 500)
blu = (0, 0, 255)
red = (255, 0, 0)
sc = (0, 0)
pr = 50
pygame.init()
screen = pygame.display.set_mode(screendim)
pygame.draw.circle(screen, blu, (250, 10), 10)
pygame.draw.rect(screen, red, pygame.Rect(0, 25, 450, 15))
pygame.display.flip()
play = True
while play:
if event.type == pygame.KEYDOWN:有什么想法吗?
发布于 2019-10-24 12:38:06
event不是一直存在的对象-您必须创建它
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
print(event) # do something with this information about key event你应该在每个教程中都能看到这一点。Program Arcade Games With Python And Pygame。
https://stackoverflow.com/questions/58534171
复制相似问题