Difference between cursor position and TextureRect position

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

Hi,

I have written this code:

func _input(event)
if InputEventScreenDrag:
item = event.position
$“Bucket1”.rect_position = item

Here ‘Bucket1’ is a TextureRect and is a child of a Node2D.

When I run the project, I find that there is constant spatial difference between the cursor and ‘Bucket1’.
The difference is about Vector2(550,350)

Why is it so? I have assigned ‘Bucket1’ to ‘item’, which is at the event position.

What am I doing wrong? Do we need to do some transform in code?

Also, I have a TouchScreen Button which is a Child of a Sprite. The Sprite is a child of a Node2D. How do I find the position of the TouchScreen Button?

Thanks in advance

:bust_in_silhouette: Reply From: Magso

The cursor position is relative to the top left of the screen so you’ll need to take away the Node2D position from the cursor position.

item = event.position - get_parent().position

Doesn’t work. Throws error.
Thanks anyway.

ashish | 2020-09-16 14:03

1 Like