mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 07:20:07 +01:00
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
24 lines
806 B
GDScript
24 lines
806 B
GDScript
extends Node
|
|
# This will track the position of every pointer in its public `state` property, which is a
|
|
# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2).
|
|
# It works by listening to input events not handled by other means.
|
|
# It also remaps the pointer indices coming from the OS to the lowest available to be friendlier.
|
|
# It can be conveniently setup as a singleton.
|
|
|
|
var state := {}
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event is InputEventScreenTouch:
|
|
if event.pressed:
|
|
# Down.
|
|
state[event.index] = event.position
|
|
else:
|
|
# Up.
|
|
state.erase(event.index)
|
|
get_viewport().set_input_as_handled()
|
|
|
|
elif event is InputEventScreenDrag:
|
|
# Movement.
|
|
state[event.index] = event.position
|
|
get_viewport().set_input_as_handled()
|