0 votes

Hello,

I am attempting to write some elegant code to allow a player to click on a sprite and drag a line out of the boundary of the sprite and release the mouse. The sprite is a child of a rigidbody2d node (and ideally this would be in the rigidbody2d script at the top of that particular scene). I have 2 questions.

I am using this "harness" to try and get the structure of the code correct.

func _input_event(viewport, event, shape_idx): #handles a mouse down within the rb2d
if event is InputEventMouseButton:
    if event.is_pressed():
        print('mouse pressed')
        _dragging = true

    else:
        print('mouse released')
        _dragging = false

elif event is InputEventMouseMotion:
    if _dragging:
        print('mouse motion')

elif event is InputEventKey:
    if event.get_scancode() == KEY_SPACE && event.is_pressed() == false:
        print('space pressed')

First question. I am seeing dual print outs for 'mouse pressed' and 'mouse released'. Why is that?

Second question, when I release the mouse outside of the rigidbody2d, I do not get the mouse released. Is the input event only available inside the confines of the collisionshape associated with that node? Do I have to handle the mouse pressed code in the input event signal handler and the mouse release code in the generic _input handler?

Thanks,

Judd

in Engine by (41 points)

Please log in or register to answer this question.

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.
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.