Skip to content
Advertisement

Pygame sprite not moving while jumping [duplicate]

I’m confused why my sprite is not moving while jumping. I’ve checked several times and changed my code over and over with no luck. My code is below and contains 3 pages, first contain the main loop, second contain the player class and third contain some game functions.

Main

JavaScript

Player

JavaScript

Game functions

JavaScript

Advertisement

Answer

Actually, the player moves when you jump, but it is hardly noticeable in the case of ” self.moving_up due to pygame.time.delay(20).
Remove delay from your code, but increase the movement of the player:

JavaScript

But use pygame.time.Clock to control the frames per second and thus the game speed.

The method tick() of a pygame.time.Clock object, delays the game in that way, that every iteration of the loop consumes the same period of time. See pygame.time.Clock.tick():

This method should be called once per frame.

JavaScript

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement