0

How do I make it so that when I press down the 'A' key for example, it keeps moving me x amount of pixels to the left as long as the 'A' button is pressed down, instead of just moving me the x amount 1 time and then waiting for me to press the button down again and again to move more?

player_pos = [WIDTH/2, 760]
player_move = 15

holdkeys = pygame.key.get_pressed()
if holdkeys[pygame.K_a]:
    player_pos[0] -= player_move
elif holdkeys[pygame.K_d]:
    player_pos[0] += player_move
if holdkeys[pygame.K_w]:
    player_pos[1] -= player_move
elif holdkeys[pygame.K_s]:
    player_pos[1] += player_move
if event.key == pygame.K_e:
    text_pos = text_offscreen
elif event.key == pygame.K_r:
    text_pos = text_onscreen

WIDTH is just the width of my game screen.

MatBBastos
  • 405
  • 6
  • 12
Aiden
  • 1
  • 1
  • Is `WIDTH` in pixels? Can you provide the value you're using? What are `text_offscreen` and `text_onscreen`? – MatBBastos Jul 14 '21 at 14:36
  • Even after adding the `import pygame` and `pygame.init()`, which are compulsory for anything to work in this context, there are still missing pieces to your code. Please refer to [this link](https://stackoverflow.com/help/minimal-reproducible-example) on how to create a minimal reproducible example in order for the community to aid you. – MatBBastos Jul 14 '21 at 14:44

0 Answers0