我正在使用 python 的 pygame 模块制作游戏,并正在尝试一种新方法,其中武器将根据 mouse 的位置旋转,并且我正在尝试找到一个可以形成玩家立方体的中心和 mouse 的 x 位置之间的直角这是代码:
点 a = (mouse.get_pos(), player cube.century)
如果我只想找到 'mouse.get_pos()' 的 x 位置,我将如何找到它?
回答1
https://www.pygame.org/docs/ref/mouse.html#pygame.mouse.get_pos声明该函数返回你想要的x和y values。
pos = mouse.get_pos()
x = pos[0]
y = pos[1]
# or just one line
x, y = mouse.get_pos();
回答2
mouse.get_pos()[0] - mouse.get_pos() 返回一个元组(列表)或者你可以把 pos = mouse.get_pos() x = pos[0]