tutorial_mouse_coords - seraph526/godot-se GitHub Wiki
#Mouse & Input Coordinates ###关于 (about) 这个小教程是为了扫除常见的一些输入上的小错误,如输入坐标,获取鼠标位置和屏幕分辨率等。
硬件显示坐标 (Hardware Display Coordinates)
使用硬件坐标在编写要在PC上运行的复杂UIs有意义,如editers,MMOs,tools等等,除了上述范畴外,没有太多意义。
唯一可靠原得到这些信息的方法是使用如下函数:
OS.get_video_mode_size() Input.get_mouse_pos() 但是,在很多情况下不建议这样使用。不要使用这些函数,除非知道你在做什么。
Viewport显示坐标 (Viewport Display Coordinates)
Godot使用viewport显示内容,viewport可以通过一些设置缩放(查看多屏幕分辨率教程)。使用函数获取鼠标坐标和viewport大小的的例子为:
func _input(ev):
Mouse in viewport coordinates
if (ev.type==InputEvent.MOUSE_BUTTON): print("Mouse Click/Unclick at: ",ev.pos) elif (ev.type==InputEvent.MOUSE_MOTION): print("Mouse Motion at: ",ev.pos)
Print the size of the viewport
print("Viewport Resolution is: ",get_viewport_rect().size)
func _ready(): set_process_input(true)