【发布时间】:2016-11-11 17:28:34
【问题描述】:
我已经用 pygame 练习了一段时间,但我无法移动我绘制的矩形。
import pygame
pygame.init()
screen_dimensions=[600,600]
rectx=0
rect=pygame.Rect(rectx,550,50,50)
screen = pygame.display.set_mode(screen_dimensions)
running=True
color = (255, 255, 255)
rect_color=(255,0,0)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running=False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_d:
rectx += 100
screen.fill(color)
pygame.draw.rect(screen, rect_color, rect)
pygame.display.update()
【问题讨论】:
-
每次绘制时都必须重新创建
rect。 -
谢谢,成功了!
标签: python python-2.7 pygame