0 votes


I have written this code:

func input(event)
if InputEventScreenDrag:
item = event.position
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

in Engine by (100 points)

1 Answer

0 votes

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
by (3,235 points)

Doesn't work. Throws error.
Thanks anyway.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.