Here is my code, very simple:
import pygame
def run_game():
pygame.init()
screen = pygame.display.set_mode((1200,800))
while True:
screen.fill((55,55,55))
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
print(pygame.mouse.get_pos())
elif event.type == pygame.MOUSEMOTION:
print(pygame.mouse.get_pos())
pygame.display.flip()
run_game()
When I click on one position, it shows the (x,y) coordinate. When I click on position one, it shows (x1,y1), then SOMETIMES after I change my mouse to position 2, and click on it, it still shows (x1,y1) instead of the correct coordinate. When this happens, if I don't move my mouse and keep click on position 2, it will keep showing (x1,y1) until I change mouse to somewhere else. Can someone explains to me why is that happened? Thanks.
event- forMOUSEBUTTONDOWNandMOUSEMOTIONyou have position inevent.pos- see more in yellow table on pygame.org/docs/ref/event.html - furas