From 23f77441bcee7b5e8fc73245121d8f4ed5bfae6e Mon Sep 17 00:00:00 2001 From: under Date: Wed, 20 Mar 2024 13:07:30 -0700 Subject: [PATCH] Move fullscreen toggle from _process to _input For whatever reason, the check being in _process prevented it from working consistently. --- FullscreenToggler.gd | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/FullscreenToggler.gd b/FullscreenToggler.gd index b5a3456..b682ccf 100644 --- a/FullscreenToggler.gd +++ b/FullscreenToggler.gd @@ -1,29 +1,29 @@ extends Node - # Called when the node enters the scene tree for the first time. func _ready(): #InputMap.action_get_events() var hotkey = ProjectSettings.get_setting("input/HotKey_ToggleFullscreen") - print(InputMap.action_get_events("character_forwards")) - print(InputMap.action_get_events("HotKey_ToggleFullscreen")) + #print(InputMap.action_get_events("character_forwards")) + #print(InputMap.action_get_events("HotKey_ToggleFullscreen")) if hotkey == null: print("PLEASE GO Project->Project Settings... , Input Map, and add HotKey_ToggleFullscreen") InputMap.add_action("HotKey_ToggleFullscreen") #InputMap.action_add_event() - print(hotkey) + #print(hotkey) -var temporarl_deadzone : float = 0 +var temporal_deadzone : float = 0 # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): + if temporal_deadzone > 0.0: + temporal_deadzone -= delta + +func _input(event: InputEvent) -> void: #Returns true when the user has started pressing the action event in the current frame or physics tick. It will only return true on the frame or tick that the user pressed down the button. #This is useful for code that needs to run only once when an action is pressed, instead of every frame while it's pressed. - if Input.is_action_just_pressed("HotKey_ToggleFullscreen") and temporarl_deadzone <= 0.0: + if event.is_action_pressed("HotKey_ToggleFullscreen") and temporal_deadzone <= 0.0: if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) - temporarl_deadzone = 0.5 - if temporarl_deadzone > 0.0: - temporarl_deadzone -= delta - + temporal_deadzone = 0.5