这是我的代码:
import pygame, sys
from pygame.locals import *
pygame.init()
window = pygame.display.set_mode((800, 600))
pygame.display.set_caption('window')
black = (0,0,0)
white = (255, 255, 255)
logo = pygame.image.load('logo.png').convert_alpha()
clock = pygame.time.Clock()
# Sprites
m1 = pygame.image.load('m1.png').convert_alpha()
m2 = pygame.image.load('m2.png').convert_alpha()
mci = 1
x, y = 0, 0
run = True
while run:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_LEFT:
x -= 10
if event.type == pygame.K_RIGHT:
x += 10
if event.type == pygame.K_UP:
y -= 10
if event.type == pygame.K_DOWN:
y += 10
window.fill(white)
pygame.draw.rect(window, black,(x,y, 50, 50))
pygame.display.flip()
clock.tick(10)
一切都显示出来了,但我无法用箭头键移动矩形,退出后总是出错,帮助..提前致谢!PS我显然是从教程中复制的,但我不确定我做错了什么?