简体   繁体   中英

Pygame mouse button down, How do I make it more smoother?

Whenever I use Pygame mouse button down event and click something, I have to not move my cursor. What I'm saying is that if I move my cursor during clicking, Pygame doesn't recognize it.

elif posx >= 204 and posy >= 476 and posx <= 280 and posy <= 504:
    screen.blit(example_picture,(205,475))
    for event in pygame.event.get():
        while event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            pygame.quit()
            sys.exit()

how do i fix it?

This is probably not the perfect answer but if you have some sort of mainloop you could do this:

old = 0
while 1: #mainloop
    if old == 0 and pygame.mouse.getpressed()[0] == 1:
        mousedownevent()    #function to be called when mouse is clicked
    old = pygame.mouse.get_pressed()

This checks every frame wether the button is pressed and was not pressed in the last frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM