Setup:
one owner:node2D
with several children:Node2D
each with a TextureRect added.
the script for the TextureRect is shared between all texturerects.
The owner:Node2D
extends Node2D
func moveit(node):
move_child(node, get_child_count()-1)
The Texturerect:
extends TextureRect
signal move
func _ready():
connect("move", get_owner(), "moveit")
var drag_pos:Vector2
var dragging
func _on_Menu_gui_input(event) -> void:
var mouse_pos:Vector2
mouse_pos= get_global_mouse_position()
if event is InputEventMouseButton:
if event.pressed and event.button_index == BUTTON_LEFT:
emit_signal("move",get_parent())
drag_pos= mouse_pos - get_parent().get_position()
dragging=1
else:
dragging = 0
elif event is InputEventMouseMotion:
if dragging and Input.is_mouse_button_pressed(BUTTON_LEFT) :
get_parent().set_position(get_global_mouse_position()-drag_pos)
Some of the windows you can click 'through', as if they are in the back.
If you change the owner:node in a Control:node it works as expected.