|
|
|
 |
Reply From: |
sparkart |
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.
Let me know if you have questions.
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.
Greg.game | 2019-06-06 23:33
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.
Greg.game | 2019-06-07 00:23
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 mouse_entered() and mouse_exited(), 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.
sparkart | 2019-06-07 23:50
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.
Greg.game | 2019-06-08 01:19
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.
sparkart | 2019-06-08 01:30
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.
Greg.game | 2019-06-08 05:11