【发布时间】:2020-11-21 16:53:24
【问题描述】:
我尝试使用.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()
【问题讨论】:
-
每次都需要擦除和重绘屏幕。
-
请修正问题中代码的Indentation。您必须在 blit 图像之前清除显示 (
screen.fill(0)) -
@Rabbid76 感谢您的评论,您可以将其发布为答案,以便我确认,立即修复身份。
标签: python python-3.x pygame