如何在pygame中将鼠标光标位置设置为对象中心?
我用绘图命令在一个700宽、500高的屏幕上大约在坐标100,100的位置画了一个小人儿,现在我想用鼠标来移动它。但是鼠标的位置和小人儿的距离很远,偏得很左右。
1 个回答
0
这个操作很简单。
比如说,
cat_image = "cat.png"
mouse_c = pygame.image.load(mouse_image).convert_alpha()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
x,y = pygame.mouse.get_pos()
x -= mouse_c.get_width()/2
y -= mouse_c.get_height()/2
screen.blit(mouse_c,(x,y))
pygame.display.update()
你需要把高度和宽度各减去一半,这样才能找到中心点。