0 votes

I have a collisionshape2d. When the user clicks on it they will hold it and drag it around until they release the button, but they'll only drag it along one axis. This means that the cursor isn't always over the object being dragged, which also means you can roll over another similarly draggable object with the mouse button pressed. Does godot give me a way to know an input event on a shape is a change from released to pressed?

in Engine by (42 points)

1 Answer

0 votes
Best answer

Yes, InputEventMouseButton has a pressed property:

func _input(event):
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
        pressed = event.pressed
by (4,169 points)
selected by

What does that do if you rolled over the collisionshape with the mouse held down? Does that not emit a new event? Maybe i'm fussing over a non-issue.

Do some tests, I think that your pickable CollisionObjects may get a pressed event, but also an entered signal, so you may need to keep track of entered before accepting pressed.

Also use input_event, not _input on CollisionObjects (unless you want to process general input).

I think i understand now. InputEventMouseButton only fires when the mouse buttons change states, so the problem i thought i was going to have won't happen. If i wanted to catch rollovers with a mouse button pressed i would need to catch the InputEventMouseMotion and poll the state of the buttons there. Thanks all.

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.