Pygame Sprite Not Moving While Jumping
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 cont
Solution 1:
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:
class Player(Sprite):
def p_movements(self):
if self.moving_left and self.rect.x > 5:
self.rect.x -= 5 # <---
if self.moving_right and self.rect.x < 765:
self.rect.x += 5 # <---
if self.moving_up:
self.rect.y -= self.y
self.y -= 2
if self.y == -30:
self.moving_up = False
self.y = 30
self.rect.bottom = 590
# pygame.time.delay(20) <--- DELETE
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.
def run_game():
# [...]
# Main loop
clock = pygame.time.Clock()
while True:
clock.tick(60)
# [...]

Post a Comment for "Pygame Sprite Not Moving While Jumping"