I have been making a basic runner game. This is only the first part. I added delay, so that when the character jumps up, it doesn't go back down automatically, but it works kind of wrong. This is the code:
import pygame
screen = pygame.display.set_mode((600, 550))
run = True
positionx = 100
positiony = 300
def update_screen():
screen.fill((0, 100, 255)) #backgorund
player = pygame.draw.rect(screen, (255, 255, 255), (positionx, positiony, 50, 80))
ground = pygame.draw.rect(screen, (0, 255, 0), (0, 380, 600, 550))
def jump():
global positiony
positiony = positiony - 60
update_screen()
pygame.time.delay(1000)
positiony = positiony + 60
update_screen()
while run:
update_screen(0)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit
if event.type == pygame.KEYDOWN and event.key == 32:
jump()
pygame.display.update()
The jump message displays, only after the 1 second delay. If I change the jump() function to something like, for example:
def jump():
global positiony
positiony = positiony - 60
update_screen()
pygame.time.delay(1000)
positiony = positiony - 60
update_screen()
Then the character will react only after the delay, even if the first update was before
Is this a glitch?