Whenever I attempt to move the yellow spaceship in my Pygame tutorial, it moves slightly but then goes back to its initial position. I'm following a tutorial, and can't seem to find the error. Can someone help me?
def draw_window(red,yellow):
gameDisplay.fill(PURPLE)
gameDisplay.blit(YELLOW_SPACESHIP, (yellow.x, yellow.y))
gameDisplay.blit(RED_SPACESHIP, (red.x, red.y))
pygame.display.update()
pygame.display.flip()
def yellow_handle_movement(keys_pressed,yellow):
if keys_pressed[pygame.K_a]: # LEFT
yellow.x -= VELOCITY
if keys_pressed[pygame.K_d]: # RIGHT
yellow.x += VELOCITY
if keys_pressed[pygame.K_w]: # UP
yellow.y -= VELOCITY
if keys_pressed[pygame.K_s]: # DOWN
yellow.y += VELOCITY
while True:
red = pygame.Rect(750, 300, SPACESHIP_WIDTH, SPACESHIP_HEIGHT)
yellow = pygame.Rect(100, 300, SPACESHIP_WIDTH, SPACESHIP_HEIGHT)
clock = pygame.time.Clock()
for event in pygame.event.get():
clock.tick(FPS)
if event.type == pygame.QUIT:
sys.exit(0)
keys_pressed = pygame.key.get_pressed()
yellow_handle_movement(keys_pressed, yellow)
draw_window(red,yellow)