Random beginner-question #13: Recognize pressed mouse entering/exiting Area2D (CollisionShape)

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

Hi everyone,

is there any way to have the movement of the pressed mouse (or held down finger on a touchscreen) recognized in terms of “I just slid into the Area2D from the outside” and respectively “I was inside the Area2D and just slid outside”…?
I would like to not accept input anymore when sliding into or out of the Area2D, but to basically make the pressed state then being ignored. (Hope that makes sense…)

Any suggestions?

The standard mouse_entered() and mouse_exited() signals of the Area2D will register the just slid inside and just slid outside the Area2D much as you described - regardless of the state of the mouse button(s) when the signal is triggered. So, that seems to solve part of your question, but you seem to be after more than just that. I don’t really follow any more of the question.

jgodfrey | 2020-09-03 00:48

Again you can read my mind and understand it better than I do…

Trying out all these functions of a button I’d like to create makes me stumble over all kinds of little issues whenever I thought I nailed something, so in this case, following your suggestions on earlier questions, I felt like I needed the state of mouse_entered/exited “remembered and forgotten” at the same time, which wouldn’t work.

So I came up with a combination of my earlier approach of a “run-until-the-end-timer” and your suggested “quit-when-release-timer” and… nailed it! (For now.) I uploaded an example here: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free so please feel free to check it out (and optimize to your liking if you want to : )

What I had a hard time to solve in the end was occasional inputs outside the Area2D and signals automatically following yields where they shouldn’t etc., but now everything seems to work just fine. It’s hacky without a doubt and I am absolutely sure that there are much more elegant ways to achieve the same result, but my beginner-ambitions certainly are very satisfied for the moment.
On to the next challenge! (Which will be this functionality put on a checkbox-button…)

pferft | 2020-09-03 11:01

Glad you got things working. I’ll try to check out your project sometime soon.

jgodfrey | 2020-09-03 14:04