game/godot

Godot3 API - Mouse and input coordinates

C/H 2018. 10. 30. 08:30

Mouse and input coordinates

About

The reason for this small tutorial is to clear up many common mistakes about input coordinates, obtaining mouse position and screen resolution, etc.
이 작은 자습서를 사용하는 이유는 입력 좌표, 마우스 위치 및 화면 해상도 등에서 자주 발생하는 많은 실수를 정리해야하기 때문입니다.

Hardware display coordinates

Using hardware coordinates makes sense in the case of writing complex UIs meant to run on PC, such as editors, MMOs, tools, etc. Yet, it does not make as much sense outside of that scope.
하드웨어 좌표를 사용하는 것은 편집자, MMO, 도구 등 PC에서 실행될 복잡한 UI를 작성하는 경우에 유용합니다. 그러나, 그것은 그 범위 밖에서 많은 의미를 가지지 않습니다.

Viewport display coordinates

Godot uses viewports to display content, and viewports can be scaled by several options (see Multiple resolutions tutorial). Use, then, the functions in nodes to obtain the mouse coordinates and viewport size, for example:
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_rect().size)

Alternatively it's possible to ask the viewport for the mouse position:
또는 뷰포트에 마우스 위치를 요청할 수도 있습니다.

get_viewport().get_mouse_position()


반응형

'game > godot' 카테고리의 다른 글

Godot3 API - Input  (0) 2018.11.02
Godot3 API - Customizing mouse cursor  (0) 2018.11.01
Godot3 API - InputEvent  (0) 2018.10.29
Godot3 API - Audio Streams  (0) 2018.10.27
Godot3 API - Audio Buses  (0) 2018.10.26