drawing order v.s. selectting order of texturerects parented to Node2D ; v.s. parented to Control node.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Black Monkey

I have a few Texturerects, each parented to their own Node2d node.
By using;

move_child(node, get_child_count()-1) 

in the root node, I can change the order in witch they are drawn.
But if I try to select them with the mouse, strange things happen: sometimes a texture
that is drawn in front, behaves as if it is further back.
Now, if I parent them to a Control node in stead of a Node2D, the behavior is,
as I would expect.

:bust_in_silhouette: Reply From: Ertain

The reason for this behavior (for a Control node) is that those nodes are related to the user interface. TextureRect is meant to take user interface input (e.g. mouse clicks) while Node2D is a general node meant for anything related to the CanvasItem node. Since Control nodes include responding to the mouse, it may be preferable to use those nodes.

Thanks for the quick response.
I get what you’re saying, but still:
In both cases the TextureRects are drawn in the right order (as in the order of the parents in the tree).
So why is the input-order wrong? (what matters the parent?)

Black Monkey | 2020-08-21 23:55

Maybe it would help if I saw your node tree, or the code you were using.

Ertain | 2020-08-22 22:32

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:
    		drag_pos= mouse_pos - get_parent().get_position()
    		dragging = 0
    elif event is InputEventMouseMotion:
    	if dragging and Input.is_mouse_button_pressed(BUTTON_LEFT)	:

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.

Black Monkey | 2020-08-23 02:03