【发布时间】:2021-02-06 01:56:47
【问题描述】:
我正在尝试在 Pygame 中制作一个移动的矩形。我知道我首先需要使用我拥有的 pygame.draw.rect()。我暂时使用在线 IDE,Repl.it。我只需要确保这段代码是正确的。
import pygame, sys
pygame.init()
screen = pygame.display.set_mode((1000,600))
x = 500
y = 300
white = (255,255,255)
player = pygame.draw.rect(screen, white, (x,y,50,40))
while True:
for event in pygame.event.get():
if pygame.event == pygame.QUIT:
pygame.QUIT
sys.exit()
if pygame.event == pygame.KEYDOWN:
if pygame.key == pygame.K_LEFT:
x -= 5
if pygame.event == pygame.K_RIGHT:
x += 5
pygame.display.update()
感谢您的意见。
【问题讨论】: