2014-10-05 63 views
0

每當我使用Pygame鼠標按鈕按下事件,並點擊某些東西,我不得不移動我的光標。我所說的是,如果我在點擊過程中移動光標,Pygame就不會識別它。Pygame鼠標按鈕向下,我如何使它更平滑?

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() 

我該如何解決?

回答

0

這可能不是最完美的答案,但如果你有某種形式的主循環,你可以這樣做:羯羊按下按鈕,並在最後一幀未按

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() 

這將檢查每一幀。