xxxxxxxxxx
import pygame
pygame.init()
DISPLAY = pygame.display.set_mode((640, 480))
cursorImg = pygame.image.load('cursor.png')
# Hide cursor and initialise cursor rectangle
pygame.mouse.set_visible(False)
cursorImgRect = cursorImg.get_rect()
# Main game loop
running = True
while running:
# Draw cursor
cursorImgRect.center = pygame.mouse.get_pos()
DISPLAY.blit(cursorImg, cursorImgRect)
# Quit the game if they close the program
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
pygame.quit()
xxxxxxxxxx
for event in pygame.event.get():
# Check for mouse left click
if event.type == pygame.MOUSEBUTTONDOWN:
# List of sprites under the mouse cursor
mousePos = pygame.mouse.get_pos()
clicked_sprites = [s for s in sprites if s.rect.collidepoint(mousePos)]
xxxxxxxxxx
pygame.mouse.set_visible(False)
cursor_img_rect = cursor_img.get_rect()
while True:
# in your main loop update the position every frame and blit the image
cursor_img_rect.center = pygame.mouse.get_pos() # update position
gameDisplay.blit(cursor, cursor_rect) # draw the cursor