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.

  • Instead of delay, try to remember current time. And when checking second time, check if more than a defined limit passed. – mcsim May 10 '17 at 12:45
  • The code comes from [this answer](http://stackoverflow.com/a/42692238/6220679). 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. – skrx May 10 '17 at 16:11

1 Answers1

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