我试图找到鼠标光标的 x 位置

im trying to find the x position of the mouse cursor

我正在使用 python 的 pygame 模块制作游戏,并且正在尝试一种新方法,武器会根据鼠标的位置旋转,我正在尝试找到一个在玩家立方体的中心和鼠标的 x 位置之间形成直角的点 这是代码:

point_a = (mouse.get_pos(), player_cube.centery)

如果我只想找到'mouse.get_pos()'的x位置,我该如何找到它?

mouse.get_pos()[0] - mouse.get_pos() returns 一个元组(列表) 或者你可以把 pos = mouse.get_pos() x = 位置[0]

The pygame documentation说明函数returns你想要的x和y值。

pos = mouse.get_pos()
x = pos[0]
y = pos[1]

# or just one line
x, y = mouse.get_pos();