我尝试使用.blit但出现问题,这是进一步解释我的问题的屏幕截图:
随着我的鼠标移动,图像似乎在屏幕上被弄脏了
代码:
import pygame
import keyboard
black = (0,0,0)
white = (255, 255, 255)
pygame.init()
screen = pygame.display.set_mode((600, 400))
screen.fill(black)
screen.convert()
icon = pygame.image.load('cross.png')
pygame.display.set_icon(icon)
pygame.display.set_caption('MouseLoc')
cross = pygame.image.load('cross.png')
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT or keyboard.is_pressed(' '):
running = False
mx, my = pygame.mouse.get_pos()
screen.blit(cross, (mx-48, my-48))
print(my, mx)
pygame.display.update()
Run Code Online (Sandbox Code Playgroud)