#I'm trying to make a duck hunt style game and I need the mouse to turn into a crosshair that follows around the mouse. I got it to follow it around but it just appears not on the mouse but in the bottom left corner for some reason.
#this is my full code right now:
import pygame
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) #setting screen dimensions
fps = pygame.time.Clock()
fps.tick(60)
pygame.init()
color = (255, 255, 255)
screen.fill(color)
pygame.mouse.set_visible(False) #makes the mouse invisible
gun = pygame.image.load(r"C:\Users\Ben\Downloads\download (3).png") #gun image
crosshair = pygame.image.load(r"C:\Users\Ben\Downloads\2783540c8c81da4 (1).png") #crosshair image
gun = pygame.transform.rotate(gun, 90) #rotates gun 90 degrees
gun_position = (375, 350)
screen.blit(gun, gun_position) #displays gun at gun_position coordinates
pygame.transform.rotate(gun, 180) #rotates gun
pygame.display.flip()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEMOTION:
mouse_position = pygame.mouse.get_pos()
screen.blit(crosshair, mouse_position)
pygame.display.update()
pygame.quit()
It seems to work fine for me. But, I'm not sure whether you want the mouse to appear or not. Your code is making the mouse invisible and putting the sprite on the mouse. I don't know how it can follow the mouse around but still be in the corner.
So, as far as I can tell, there is nothing wrong with your code.
Also, just a few tips:
The fps.tick(60) should be called every frame, so put in your while loop.
Remember to draw a background or something to the screen every frame so it covers up what you drew to the screen last frame.