+1 vote

Hello Godot community,

Below is the structure I'm having :
------> Area2D
------------> TextureRect
------------> CollisionShape2D

When I connect the inputevent signal of my node Aread 2D to the main gd script (in the same scene), the follow code is not working :

func _on_DominoePieceA2D_input_event(viewport, event, shape_idx):
    if (event is InputEventScreenTouch):
        if (event.is_pressed()):

I do receive an event, but is_pressed returns false, moreover, it's not working when I export it on phone.
So I was wondering if the structure I'm having (control and Node2D) is a valid structure.

What I'm trying to do is having images in a container, I'm trying to perform a drag&drop/click on those in order to move them into another container, so if my implementation is not valid, I'm open for suggestions :).

Thank you for any help.

in Engine by (24 points)

2 Answers

0 votes
Best answer

Hi Seli,
I would recommend using Texturerects without Areas and collision-shapes. Areas are mostly for receiving information from other physics driven elements (like collisions or if a body enters). You can use gui_input(event) signal. You should also have a look at the GUI Drag and Drop Demo. If you have any further questions of how to use this tips feel free to ask.

Good luck. Jowan-Spooner

P.S. I don't know why what you do is not working and it's porbably not completely wrong and should somehow be possible, nevertheless the way I described above is more common for what you seem to try.

by (864 points)
selected by
0 votes

I struggle for the same problem as well And I think what you write is right! The problem is that The Event System...
The event is consumed by UI elements and not be sent to Physic world. That is the dot engine design And I think that is wrong in 2d games.
The best practise is to test any event in UI and physic world all and select the nearest (ui element OR physic object) to trigger the event. OR the UI element can consume the EVENT and then resend to the physic world. Both is OK(This way, the problem is some event will not fit like body_enter event, the parent UI shape is not the same as child Area2d, But the init event like mouse move is ok).
Thanks, I think the dotengine should fix this.
3d Game is the same, need a function that can resend the init event to physic world.

by (18 points)
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 [email protected] with your username.