Python Forum
Thread Rating:
  • 4 Vote(s) - 3.25 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame Error
#1
Hi, here is my code :
import pygame
pygame.init()

screen = pygame.display.set_mode((1000,750))

vie = True
clock = pygame.time.Clock()
x = 50
y = 50
points_x = [500]
points_y = [375]

clock = pygame.time.Clock()
color = (255, 100, 0)


def mouvement():
    screen.fill((0, 0, 0))
    for loop in range(len(points_x) - 1):
        points_x[len(points_x) - loop] = points_x[len(points_x) - loop - 1]
        points_y[len(points_y) - loop] = points_y[len(points_y) - loop - 1]
    for loop in range(len(points_x)):
        pygame.draw.rect(screen, color, pygame.Rect(points_x[loop], points_y[loop], 60, 60))
        
            
            
           

while True:
    pressed = pygame.key.get_pressed()

    ancien_x = points_x[0]
    ancien_y = points_y[0]
    
    if pressed[pygame.K_UP]:
        points_y[0] -= 3
        mouvement()
    elif pressed[pygame.K_DOWN]:
        points_y[0] += 3
        mouvement()
    elif pressed[pygame.K_LEFT]:
        points_x[0] -= 3
        mouvement()
    elif pressed[pygame.K_RIGHT]:
        points_x[0] += 3
        mouvement()

    pygame.draw.rect(screen, color, pygame.Rect(x, y, 60, 60))
    
    clock.tick(60)

But, the screen don't show anything. I don't know why ...
Reply
#2
after clock.tick(60) add the following line
pygame.display.update()
This needs to be done once ever in the main game loop.
Recommended Tutorials:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020