Hello I'm trying to move a character with with +1 pixel every loop while a button is held.
However since Windows has a built in delay on holding down a key then simply using a code like below doesn't work. The code is meant to give a certain speed while the character is on the ground and a slower, but increasing speed if in the air.
I have read some comment about how "Using keys to directly move the character" isn't the right way to solve the problem. However I cannot figure out how to go about this.
Thankful for any help!
Key presses:
keys = pygame.key.get_pressed()
if keys[pygame.K_a]:
player.go_left()
if keys[pygame.K_d]:
player.go_right()
Move character functions:
def go_left(self):
if self.air == False:
self.change_x = -5
else:
self.change_x -= 0.5
def go_right(self):
if self.air == False:
self.change_x = 5
else:
self.change_x += 0.5