0

The rectangle should be moving but it only moves like one inch I cant figure out what i'm doing wrong, so yeah

import pygame,random,os
pygame.init()
rand=random.Random()
#use https://www.qr-code-generator.com/

#Setup
WIDTH,HEIGHT=210,210
WIN=pygame.display.set_mode((WIDTH,HEIGHT))
pygame.display.set_caption("QR code generator")
WIN.fill((255,255,255))
x=3





run=True
while run:


  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      run=False
  pygame.draw.rect(WIN, (0,0,0), pygame.Rect(x,0,10,10))
  
  
  pygame.display.update()
  x-=1

the black square should just move right across the top but it moves a little then doesnt at all.

  • You are just drawing a new rectangle and moving it left of the edge of the screen. Try clearing your screen (use `WIN.fill`) each time and moving it right instead `x+=1`. – scotty3785 Jan 10 '22 at 16:00
  • Also, your code will move the rectangle very quickly. Add a `clock.tick` like `clock.tick(40)` to the end of your while loop – scotty3785 Jan 10 '22 at 16:01
  • Closing the question was hardly helpful for the OP. – scotty3785 Jan 10 '22 at 16:07

0 Answers0