0

I am very new to pygame, and have been following this tutorial. one problem is that the movement is very inconsistent and it is hard to turn left and right quickly. I think this is because when a key is released, it is programmed to stop ALL movement, so other keys pressed at the same time are blocked.

The way i have fixed this is by making 2 variables for the horizontal movement, so now it kind of looks like this.

if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                player_left_change = -0.3
            if event.key == pygame.K_RIGHT:
                player_right_change = 0.3
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT:
                player_left_change = 0
            if event.key == pygame.K_RIGHT:
                player_right_change = 0

and

playerX += player_left_change
playerX += player_right_change

This works really well, it just looks inefficient. Are there any other ways to do this?

0 Answers0