InputEventScreenTouch not is_pressed?

DanielKotzerDanielKotzer Posts: 69Member
edited September 21 in Exporting

Hi,

At first I was using InputEventMouseButton and is_pressed / not is_pressed to detect mouse down and mouse up events, but since I want my game to work on touch screens, I started using InputEventScreenTouch, but then I can detect is_pressed to know if the user is touching the screen, equivalent to mouse down, what do I do in order to detect a "mouse up"? or in other words, is there a way (better to check it constantly on a frame enter event) to know when the user had stopped touching the screen?


Tags :

Best Answer

  • DanielKotzerDanielKotzer Posts: 69
    Accepted Answer

    I don't know why it didn't work for me before, but this code is working:

    func _unhandled_input(event):
        if event is InputEventScreenTouch:
    
            if event.is_pressed():  # touch down.
                mouse_button_pressed = true
                new_mouse_pos = event.get_position()
                new_mouse_original_pos = event.get_position()
            elif not event.is_pressed():  # touch released.
                mouse_button_pressed = false
                if new_mouse_original_pos.distance_to (event.get_position()) < 10:
                    new_mouse_click = true;
    

Answers

  • DanielKotzerDanielKotzer Posts: 69Member
    Accepted Answer

    I don't know why it didn't work for me before, but this code is working:

    func _unhandled_input(event):
        if event is InputEventScreenTouch:
    
            if event.is_pressed():  # touch down.
                mouse_button_pressed = true
                new_mouse_pos = event.get_position()
                new_mouse_original_pos = event.get_position()
            elif not event.is_pressed():  # touch released.
                mouse_button_pressed = false
                if new_mouse_original_pos.distance_to (event.get_position()) < 10:
                    new_mouse_click = true;
    

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file