I've been testing out movement for a fighting game that I'm creating in Python.
The problem is that when I try to move the sprite, it moves correctly to the left, but only ever works in that direction. I think the problem is with my event handling loop, but I don't have much experience so I have no idea how to solve the problem. Googling and spending a while doing trial and error was no help.
My main loop looks like this:
pressedLeft = None pressedRight = None pressedUp = None pressedDown = None while True: #event handling for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_a: pressedLeft = True elif event.key == pygame.K_d: PressedRight = True elif event.key == pygame.K_w: PressedUp = True elif event.key == pygame.K_s: PressedDown = True elif event.type == pygame.KEYUP: if event.key == pygame.K_a: pressedLeft = False elif event.key == pygame.K_d: PressedRight = False elif event.key == pygame.K_w: PressedUp = False elif event.key == pygame.K_s: PressedDown = False # movement if pressedLeft: profx -= 5 elif pressedRight: profx += 5 elif pressedUp: profy -= 5 elif pressedDown: profy += 5 DisplaySurf.fill(white) DisplaySurf.blit(profImg, (profx, profy)) pygame.display.update() fpsClock.tick(FPS)