Skip to content

Commit b6543b2

Browse files
committed
Hide mouse pointer after no movement is registered
Add a new global that, whenever the mouse is moved, restarts a 3 seconds one-shot timer. Upon timeout, hide the mouse. This makes the mouse visible only when using it. Assuming that people is used to move the mouse in order to find its position on screen. #807
1 parent 60a3fdc commit b6543b2

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

project.godot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CameraShake="*res://scenes/globals/camera_shaker/camera_shake.tscn"
3333
InputHelper="*res://addons/input_helper/input_helper.gd"
3434
AspectRatioDebugger="*res://scenes/globals/aspect_ratio_debugger/aspect_ratio_debugger.tscn"
3535
InputGlobal="*res://scenes/game_elements/props/hint/input_key/InputHintManager.gd"
36+
MouseManager="*res://scenes/globals/mouse_manager/mouse_manager.tscn"
3637

3738
[debug]
3839

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: The Threadbare Authors
2+
# SPDX-License-Identifier: MPL-2.0
3+
extends Node
4+
5+
@onready var hide_timer: Timer = %HideTimer
6+
7+
8+
func _input(event: InputEvent) -> void:
9+
if event is InputEventMouseMotion:
10+
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
11+
hide_timer.start(3)
12+
13+
14+
func _on_hide_timer_timeout() -> void:
15+
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://rw3yh3185lpn
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://cnihu6fwcogid"]
2+
3+
[ext_resource type="Script" uid="uid://rw3yh3185lpn" path="res://scenes/globals/mouse_manager/mouse_manager.gd" id="1_u8i10"]
4+
5+
[node name="MouseManager" type="Node"]
6+
script = ExtResource("1_u8i10")
7+
8+
[node name="HideTimer" type="Timer" parent="."]
9+
unique_name_in_owner = true
10+
wait_time = 3.0
11+
one_shot = true
12+
autostart = true
13+
14+
[connection signal="timeout" from="HideTimer" to="." method="_on_hide_timer_timeout"]

0 commit comments

Comments
 (0)