Files
godot-demo-projects/mobile/multitouch_view/Main.gd
Hugo Locurcio bac1e69164 Use static typing in all demos (#1063)
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).
2024-06-01 12:12:18 +02:00

23 lines
659 B
GDScript

extends Node2D
func _process(_delta: float) -> void:
# Keep redrawing on every frame.
queue_redraw()
func _draw() -> void:
# Get the touch helper singleton.
var touch_helper: Node = $"/root/TouchHelper"
# Draw every pointer as a circle.
for ptr_index: int in touch_helper.state.keys():
var pos: Vector2 = touch_helper.state[ptr_index]
var color := _get_color_for_ptr_index(ptr_index)
color.a = 0.75
draw_circle(pos, 40.0, color)
## Returns a unique-looking color for the specified index.
func _get_color_for_ptr_index(index: int) -> Color:
var x := (index % 7) + 1
return Color(float(bool(x & 1)), float(bool(x & 2)), float(bool(x & 4)))