0

When i click on the exit button or just left click i often need to click more than once before it registers my input and does what i want it to do in pygame. I have no idea what is causing this to happen.

Here is my game-loop:

while running:
    window.fill(light_black)

    for event in pygame.event.get():
        print(event)  # Debug
        if event.type == pygame.MOUSEBUTTONUP:
            mpos_x, mpos_y = pygame.mouse.get_pos()
            boids.append(CreateBoid(mpos_x, mpos_y))

    for boid in boids:
        boid.draw()

    pygame.display.update()

    if check_exit():
        running = False

I'm using the PyCharm IDE if that could have anything to do with it.

Thanks

EDIT: It was solved by removing the check_exit() function

Sorrells
  • 69
  • 7
  • What does the `check_exit()` function do? Usually you check for the `pygame.QUIT` event in the event loop. – Ted Klein Bergman Sep 27 '16 at 21:41
  • @TedKleinBergman `check_exit()` simply returns true if `event.type == pygame.QUIT` – Sorrells Sep 28 '16 at 06:34
  • I tried removing `check_exit()` and it runs smoothly now. Which is pretty wierd – Sorrells Sep 28 '16 at 06:44
  • 1
    The problem is that the event queue is consuming every event as you iterate through it. That means that in order for the `check_exit()` function to find the event `QUIT` you have to click the exit button during the time between the first event loop and `check_exit()`. This is a very short time and might require multiple tries before timing it correctly. – Ted Klein Bergman Sep 28 '16 at 08:55
  • Ah, that makes sense. Thanks a ton :D – Sorrells Sep 28 '16 at 09:24

0 Answers0