I have tried many other methods, including creating a rectangle and iterating the y coordinate but that creates a long line which i do not want. This is my OOB approach to it, which is not great, but please bear with me as i am a beginner. I have also tried out the code in the documentation and it also created a line of rectangles. Kindly help me
class Rectangle:
def __init__(self, x, y):
self.x = x
self.y = y
self.rect=pygame.draw.rect(window,(255,0,0),pygame.Rect(x,y,50,50))
def draw_shape(self,x,y):
self.rect=pygame.draw.rect(window,(255,0,0),pygame.Rect(x,y,50,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()
strong text
You are not clearing the screen so the old rectangles are still there.
screen.fill((0,0,0))
will fill it with black. Also take update out of draw shape. You should have one update method to update everything and one draw method to draw everything.