Godot Version
Godot 4
Question
Hi everyone,
I’m a beginner making a simple clicking game in Godot 4. A circle appears at a random position on screen, and when the player clicks it, it jumps to a new random position. The game has a 30-second countdown and counts how many circles the player clicks.
I would like to also measure the (reaction time) – meaning the time between the circle appearing at its new position and the moment the player clicks it – and display it on screen.
Here is my current circle script (attached to an Area2D):
extends Area2D
func _ready():
random_position()
func random_position():
var screen_size = get_viewport_rect().size
var x = randf_range(0, screen_size.x)
var y = randf_range(0, screen_size.y)
position = Vector2(x, y)
func _input_event(_viewport, event, _shape_idx):
if event is InputEventMouseButton and event.pressed:
if get_parent().time_left > 0 and not get_parent().game_over:
get_parent().add_point()
random_position()
I think I need to save a start_time using Time.get_ticks_msec() when the circle appears, and then calculate the difference when the player clicks. But I’m not sure where exactly to store the start time and how to display it correctly.
Any help is appreciated, thank you!