Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
마우스 및 입력 좌표
소개
이 작은 튜토리얼의 이유는 입력 좌표, 마우스 위치 및 화면 해상도 획득 등과 관련된 많은 일반적인 실수를 해결하기 위한 것입니다.
하드웨어 디스플레이 좌표
편집기, MMO, 도구 등과 같이 PC에서 실행하기 위한 복잡한 UI를 작성하는 경우 하드웨어 좌표를 사용하는 것이 합리적입니다. 그러나 해당 범위를 벗어나면 그다지 의미가 없습니다.
뷰포트 표시 좌표
Godot는 컨텐츠를 표시하기 위해 뷰포트를 사용하며, 뷰포트는 여러 옵션으로 크기를 조정할 수 있습니다(다양한 해상도 튜토리얼 참조). 그런 다음 노드의 함수를 사용하여 마우스 좌표와 뷰포트 크기를 가져옵니다. 예:
func _input(event):
# Mouse in viewport coordinates.
if event is InputEventMouseButton:
print("Mouse Click/Unclick at: ", event.position)
elif event is InputEventMouseMotion:
print("Mouse Motion at: ", event.position)
# Print the size of the viewport.
print("Viewport Resolution is: ", get_viewport().get_visible_rect().size)
public override void _Input(InputEvent @event)
{
// Mouse in viewport coordinates.
if (@event is InputEventMouseButton eventMouseButton)
{
GD.Print("Mouse Click/Unclick at: ", eventMouseButton.Position);
}
else if (@event is InputEventMouseMotion eventMouseMotion)
{
GD.Print("Mouse Motion at: ", eventMouseMotion.Position);
}
// Print the size of the viewport.
GD.Print("Viewport Resolution is: ", GetViewport().GetVisibleRect().Size);
}
또는 뷰포트에 마우스 위치를 요청할 수도 있습니다.
get_viewport().get_mouse_position()
GetViewport().GetMousePosition();
참고
마우스 모드가 Input.MOUSE_MODE_CAPTURED``로 설정된 경우 ``InputEventMouseMotion``의 ``event.position 값이 화면 중앙에 위치합니다. 마우스 이동 및 위치 변경을 처리하려면 event.position 및 event.velocity 대신 ``event.relative``를 사용하십시오.
mouselook과 같은 기능을 구현할 때 event.relative 및 event.velocity 대신 event.screen_relative 및 ``event.screen_velocity``를 사용하여 마우스 움직임이 :ref:`다중 해상도 <doc_multiple_solutions>`에서 동일하게 동작하도록 하는 것이 좋습니다.