|
|
|
|
Reply From: |
exuin |
If you look at this diagram from the InputEvent doc page
you can see that Controls will always get InputEvents before Area2Ds regardless of node hierachy. So rearranging the nodes won’t cut it. The _input()
function gets the event ahead of everything else, however. You can use the _input()
function on the draggable node in order to catch it before the ColorRect can.
What I meant with rearrange was deleting the ColorReact altogether in case all it did was blocking the input.
ColorRect in background is used to prevent me from interacting with what is beyond it
But in case you really need ColorRect you can use _input() like Exuin said.
Wow, I got it.
That hint really seems to solve my problems. But could any of you show me a summarize way in code of how I achieve this? I am a really newbie in Godot for now.
can be just the func input to change the order wich the node is catch
And if that helps, that is my actual code for draggable Node2D
extends Node2D
var selected = false
var final = false
var rest_nodes = []
var final_point
#var pos_origin = global_position
func _ready():
rest_nodes = get_tree().get_nodes_in_group("Zone")
func _physics_process(delta):
if selected:
global_position = lerp(global_position, get_global_mouse_position(), 25*delta)
else:
if final:
global_position = lerp(global_position, final_point, 10*delta)
#else:
# global_position = lerp(global_posiition, pos_origin, 10*delta)
func _input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT and not event.pressed:
selected=false
var shortest_distance = 75
for child in rest_nodes:
var distance = global_position.distance_to(child.global_position)
if distance<shortest_distance:
final_point = child.global_position
shortest_distance = distance
final=true
func _on_Area2D_input_event(viewport, event, shape_idx):
if Input.is_action_pressed("click"):
if final==false:
selected=true
SubBut | 2021-04-23 23:29
Sure, I will help you when I am not busy
Thank u, I really appreciate.
SubBut | 2021-04-24 15:31
Hmm, so the code you have doesn’t work? It looks like it should work. How exactly doesn’t it work?
It works, I just wanted to know how I apply that hint with the input thing you gave me, to “ignore” ColorRect, in my code.
Sorry if Im making me hard to understand.
SubBut | 2021-04-25 14:28
The code you have already ignores the ColorRect since the _input()
function captures the input event before the ColorRect gets it.
Oh, so I dont know why this is happening. I guess I will have to get rid of the ColoRect, right?
SubBut | 2021-04-25 19:18
Does it work without the color rect? Are you sure the color rect is the issue?
Yeah, it works, even if I just assign the Inspector>Mouse>Ignore, it already works.
SubBut | 2021-04-25 20:18