0 votes

Hi. I have created a control scheme using ColorRect nodes (inherited from Control). When using a mouse everything works brilliantly - "mouse _entered()" and "mouse _exited()" work as expected.

When trying to use touch input on android device, a "mouse _entered()" signal is only generated when ColoRect node is first touched. No subsequent "mouse _entered()" or "mouse _exited()" signals are generated when I move my finger on the screen between ColorRect control nodes (was hoping that my finger movement while continually touching the screen would be like hovering a mouse cursor).

Do I need to scrap my interface logic or is there a solution to this? Would rather not re-tool logic to poll position and check if it is within control nodes , etc. Seems overly complicated but am glad to hear ANY suggestions. Thank you!

asked Jun 6, 2019 in Engine by Greg.game (14 points)
edited Jun 6, 2019 by Greg.game

1 Answer

0 votes

You can override the following Control function:

void _gui_input ( InputEvent event ) virtual

Here's an example

extends Control

func _gui_input(event):
   if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
       print("Left mouse button was pressed!")

See the following link for more help.
https://docs.godotengine.org/en/3.1/tutorials/gui/custom_gui_controls.html?highlight=input%20event

Let me know if you have questions.

answered Jun 6, 2019 by sparkart (327 points)

I could very well be missing the answer in your reply, but I think what you've shown me requires a button press and that is what I'm trying to avoid and what I have working when using an actual mouse instead of mouse emulation via touch.

So if I have two adjacent control nodes and I touch one and then leave my finger on the screen while moving it to the second node, I want the second node to detect I have entered it without having to signal a button press (without having to raise my finger and bring it down again). I want to glide my finger over and have it detected in the second node when I enter it.

It works with a hovering mouse cursor using "mouse _entered()" without having to ever press the mouse button.

Thank you for your reply and please elaborate if I missed the point or you have another suggestion.

I overrode the Control function like in the example you gave - with the following logic in the second control node entered:

    if event is InputEventMouseMotion:

Unfortunately it still only detects it when I tap in the 2nd node, not when I glide my finger over to it.

extends Control

func _gui_input(event):
       print("Inside")

Try that, although it doesn't have an exit signal.

I've done a test using notifications, which should work. I'm not entirely sure if this is the same as using the mouseentered() and mouseexited(), if it is, it probably will have the same problem you're experiencing:

func _notification(what):
    match what:
        NOTIFICATION_MOUSE_ENTER: 
            print("Entered")
            color = Color.green
        NOTIFICATION_MOUSE_EXIT:
            color = Color.red
            print("Exit")

I haven't tested it on mobile because I haven't set it up yet. But if it doesn't work, it might be a bug.

If you don't mind sharing your project I'd be willing to check it out, maybe there's something being overlooked.

Thanks again sparkart , but your notifications produce the same results as the mouse enter and exit node signals (I think they really are the same under the covers). It all works peachy keen with mice but touch is a different story. The node doesn't relinquish control and exit until the finger is raised and brought back down outside the node (so another node won't react to an enter signal/notification until that has happened). Hovering a mouse cursor works perfectly and respects the node's boundaries. I might create a sample project and lodge an issue on GitHub.

It might be an issue with the mouse coordinates not being updated until a release. Try drawing the mouse coordinates to screen, if that's the case the mouse coordinates should not update until you release your finger.

I might have some time this week to look into it and see if I can resolve the issue.

The mouse coordinates continue updating while the finger is still down even after moving outside of the Control node. For example, the x position goes into the negative if the touch goes outside the node to the left. This continues until the touch is released.

I'm learning a lot through this process and your suggestions.

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 How to use this Q&A? before posting your first questions.