问题描述
我尝试了许多其他方法,包括创建一个矩形和迭代 y 坐标,但这会创建一条我不想要的长线。这是我的 OOB 方法,不是很好,但请耐心等待,因为我是初学者。我还尝试了文档中的代码,它还创建了一行矩形。请帮帮我
class Rectangle:
def __init__(self,x,y):
self.x = x
self.y = y
self.rect=pygame.draw.rect(window,(255,0),pygame.Rect(x,y,50,50))
def draw_shape(self,y):
self.rect=pygame.draw.rect(window,50))
pygame.display.update()
def move_shape(self,x):
for i in range(0,10):
x=x+50*i
self.draw_shape(x,0)
recT= Rectangle(0,0)
recT.draw_shape(0,0)
while running==True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
running=False
recT.move_shape(0)
pygame.display.update()
强文本
解决方法
您没有清除屏幕,所以旧的矩形仍然存在。
screen.fill((0,0))
将用黑色填充它。还要从绘制形状中取出更新。你应该有一种更新方法来更新所有内容,一种绘制方法来绘制所有内容。