I'm new to python and I'm trying to make a simple platformer game using pygame. My issue is that when I use a while
loop to make a block fall until it hits the bottom of the screen, it travels there all at once and I can't see it happening. However when I move the block side to side using if
statements, I can see that happening. How can I slow down the falling block down so it's visible?
I was following a tutorial for the most part, but wanted to add my own thing.
clock = pygame.time.Clock()
fps = 60
run = True
while run:
clock.tick(fps)
keys = pygame.key.get_pressed()
if keys[pygame.K_a] and x > 0:
x = x - 5
if keys[pygame.K_d] and x < (500 - width):
x = x + 5
if keys[pygame.K_s]: #this is the portion that is too fast.
while y < (500 - height):
y = y + 5
player = pygame.draw.rect(screen, (player_color), (x,y,width,height))
pygame.display.update()
I tried putting the entire while ... y = y + 5
code into an if
as well; that slowed it down, but it only moved when I held down the s
key.