PYTHON- PYGAME: How do I know if a mouse clicked on an image? -
this question has answer here:
- pygame mouse clicking detection 3 answers
i'm making basic level game if click card, picture show. pictures randomly chosen. , far, have assigned random pictures card , cards shown face down. if click card, want assigned picture (which in dictionary) show.
i want know how can detect if i've clicked on image (of card) because x,y coordinates of image on top left. right now, i'm trying figure out way use xy coordinates of mouse click detect if image has been clicked on. there way use 'collide' or making things complicated? i'm beginner programmer i'm still trying learn python , pygame :|
instead of hardcoding coords / using range, use collision functions:
while true: event in pygame.event.get(): if event.type == pygame.quit: sys.exit() if event.type == pygame.mousebuttondown: # set x, y postions of mouse click x, y = event.pos if ball.get_rect().collidepoint(x, y): # swap
Comments
Post a Comment