1

I don't get any errors but it doesn't work. I tried so many things but it never moves. I even copied ready scripts sometimes and they didn't move too. Please explain what am i doing wrong. Thanks from now.

import pygame
pygame.init()

screen = pygame.display.set_mode((800, 600))

red = 100
green = 100
blue = 100
top = 265
left = 365
width = 70
height = 70

pygame.draw.rect(screen, [red, green, blue], [left, top, width, height])

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    left += 0.1
    pygame.display.flip()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
nongenua
  • 13
  • 3

1 Answers1

0

Actually the rectangle does move. However you must draw the rectangle in the application loop:

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    left += 0.1

    screen.fill(0) 
    pygame.draw.rect(screen, [red, green, blue], [left, top, width, height])
    pygame.display.flip()

The typical PyGame application loop has to:

Rabbid76
  • 202,892
  • 27
  • 131
  • 174