Published
- 1 min read
move object in pygame when keydown and stop when keyup
The solution for this is noted below
move object in pygame when keydown and stop when keyup
Solution
x = 0
x_move = 0
while True:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RIGHT:
x_move = 5
elif event.type == KEYUP:
x_move = 0
x += x_move
Try other methods by searching on the site. That is if this doesn’t work