Python Forum

Full Version: My Pygame Sprite not appearing...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
My rectangle won't appear... I am using pygame. I just want a still rectangle.

import pygame

pygame.init()

#Display#
display = pygame.display.set_mode((800, 500))
pygame.display.set_caption("Magic Tales")

#Variables#

Spd = 20
x1 = 360
y1 = 250
x2 = 440
y2 = 250
fight = True

while fight:
    pygame.time.delay(20)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            fight = False






    pygame.draw.rect(display, (20, 20, 20), (400, 248, 80, 20))
        
    display.fill((0, 60, 80))
    pygame.display.update()

    












pygame.quit()

            
That because you erase it. You fill display first. Draw everything after that.
Use pygame.time.Clock to idle/sleep program.

import pygame

pygame.init()
display = pygame.display.set_mode((800, 500))
pygame.display.set_caption("Magic Tales")
clock = pygame.time.Clock()
fps = 60

fight = True
while fight:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            fight = False

    # Clear display
    display.fill((0, 60, 80))
    # draw
    pygame.draw.rect(display, (20, 20, 20), (400, 248, 80, 20))
    pygame.display.update()
    # Idle/Sleep
    clock.tick(fps)

pygame.quit()
    
(Apr-08-2020, 12:09 PM)Windspar Wrote: [ -> ]That because you erase it. You fill display first. Draw everything after that.
Use pygame.time.Clock to idle/sleep program.
Thank you!
Use pygame.time.Clock to idle/sleep program.
2048