I am trying to make a game where I can move a ship left and right by pressing down on the left and right arrow keys. The code you see below is what I currently have:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
self.ship_image_rect.x += 2
if event.key == pygame.K_LEFT:
self.ship_image_rect.x -= 2
But instead of continuous movement when I press the right or left arrow key, it moves once and stops. I have to press the arrow keys repeatedly for any meaningful movement, which is definitely not what I want to do.
How can I improve this code so that my ship will move continuously in either direction upon either arrow key being pressed?