-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.gd
More file actions
25 lines (19 loc) · 941 Bytes
/
globals.gd
File metadata and controls
25 lines (19 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
extends Node
var player = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Auto-focus window and capture mouse/keyboard
get_window().grab_focus()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
# Release mouse capture when Escape is pressed
if Input.is_action_just_pressed("kb_esc") or Input.is_physical_key_pressed(KEY_ESCAPE):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _input(event: InputEvent) -> void:
# Recapture mouse when clicking on the window
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed and Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
get_viewport().set_input_as_handled()