1

I'm having some troubble about getting a double-click (arrow RIGHT) in pygame/python. Here is my code for now:

 timer = 0 exit = True dt = 0.1 ` while exit: for event in pygame.event.get(): if event.type == pygame.QUIT: exit = False if event.type == pygame.KEYDOWN: if event.key == seta_direita: print("Moveu") if timer == 0: # First click. timer = 0.1 # Start the timer. #Click again before 0.3 seconds to double click. elif timer < 0.3: print('Dash') # Increase timer after mouse was pressed the first time. elif timer != 0: timer += dt pygame.time.delay(100) # Reset after 0.3 seconds. elif timer >= 0.3: timer = 0 

So there is.

2
  • Instead of delay, try to remember current time. And when checking second time, check if more than a defined limit passed. Commented May 10, 2017 at 12:45
  • The code comes from this answer. You have to remove the code that increases and resets the timer from the event loop and put it with one indentation level into the while loop. pygame.time.delay(100) should be removed completely. Don't just copy and paste code from SO, you have to understand how it works. Commented May 10, 2017 at 16:11

1 Answer 1

0

You currently only increment the timer when the mouse button is pressed, you should be starting the time when the button is pressed, and iterating it out if the event loop

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.