0
我用绘图命令在700,500屏幕上创建了一个基本100,100的小棒图,并且我想用鼠标移动它。鼠标出现在棒图的左侧和右侧。如何在pygame中设置鼠标光标在物体中心的位置?
我用绘图命令在700,500屏幕上创建了一个基本100,100的小棒图,并且我想用鼠标移动它。鼠标出现在棒图的左侧和右侧。如何在pygame中设置鼠标光标在物体中心的位置?
要做到这一点很简单。
例如,
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()
你需要减去一半的高度和宽度到达市中心。
你有任何代码吗? – matsjoyce 2014-10-18 09:28:36