I am making a game where a KinematicBody2D (which has a Sprite in the shape of a paint brush) moves to the new mouse click position. With this click, a Line2D also adds a new point and a line is drawn to the new position.
All this is working, however there is a problem:
Before, I move the KinematicBody2D to the new click position, I have a mouse click on a TouchScreenButton (out of many) to pick up a colour for the Line2D trail. The problem is this press also moves the KinematicBody2D. This is an undesired result. In other words, the press on the TouchScreenButton inserts the colour as well as moves the KinematicBody2D. The press should only collect the colour for the Line2D(and change the value of a flag).
Some part of the code execution must not happen when the click is on a TouchScreenButton. Anywhere else, the click is fine as it moves the KinematicBody2D as required.
I have any an idea that call-deferred may solve the problem. But I am not able to write the correct code for execution of the TouchScreenButton thread only.
Here is my code:
onready var line = get_node("../line")
var speed = 100
var velocity = Vector2(0,0)
var adjust =Vector2(0, 0)
var colour =[false, false, false, false, false, false, false, false, false,false, false, false,false]
var value = Color(0,0,0,0)
var new_position = Vector2(0,0)
velocity = Vector2()
old_position = position
new_position = get_local_mouse_position()
velocity = new_position
velocity = velocity.normalized() * speed
if velocity != adjust:
var wide = 5.0
line.width = wide
old_position = new_position
value = Color(1,0,0,1)
Please notice that in the _ready function, I tried to connect a signal for a call-deferred call. However, I am not able to insert code or function correctly. Maybe, I need a different approach altogether.