From ed77e27ecd1101f02e3d7fb83cca5a4b62dd3dca Mon Sep 17 00:00:00 2001 From: perivesta <> Date: Fri, 7 Jul 2023 22:54:40 +0200 Subject: very simple drawing --- Scripts/drawing.gd | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Scripts/drawing.gd (limited to 'Scripts') diff --git a/Scripts/drawing.gd b/Scripts/drawing.gd new file mode 100644 index 0000000..34129ac --- /dev/null +++ b/Scripts/drawing.gd @@ -0,0 +1,18 @@ +extends Node + +var drawing = false +var line: Line2D + + +func _ready(): + line = $TrackLine + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + +func _input(event): + if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: + # start/stop drawing + drawing = event.pressed + + if event is InputEventMouseMotion and drawing: + # extend the line + line.add_point(event.position) -- cgit From 2236b0c2050f98aa11c6c631ee6ddc9dd7e57df0 Mon Sep 17 00:00:00 2001 From: perivesta <> Date: Fri, 7 Jul 2023 23:26:08 +0200 Subject: follow the drawn path --- Scripts/drawing.gd | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'Scripts') diff --git a/Scripts/drawing.gd b/Scripts/drawing.gd index 34129ac..d47e161 100644 --- a/Scripts/drawing.gd +++ b/Scripts/drawing.gd @@ -1,18 +1,38 @@ extends Node var drawing = false +var driving_progress = -1 var line: Line2D +var path: Path2D func _ready(): line = $TrackLine + path = $TrackPath Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) +func _process(delta): + pass + +func _physics_process(delta): + if driving_progress >= 0: + driving_progress += delta*200 + $TrackPath/TrackFollower.progress = driving_progress + #print(driving_progress) + func _input(event): if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: - # start/stop drawing drawing = event.pressed - + if drawing: + # start a new drawing + line.clear_points() + path.curve.clear_points() + driving_progress = -1 + else: + # start driving + driving_progress = 0 + if event is InputEventMouseMotion and drawing: # extend the line line.add_point(event.position) + path.curve.add_point(event.position) -- cgit