+1 vote

How do you make it that when you get touch the screen, the touch buttons become visible and after a few seconds (maybe 5) it becomes invisible until another touch input has been performed

in Engine by (114 points)

1 Answer

+2 votes

Monitor user input for a SCREEN_TOUCH event. If detected, show the buttons and start a timer. When the timer finishes, hide the buttons.

For example:

func _ready():
    set_process_input(true)


func _input(event):
    if (event.type == InputEvent.SCREEN_TOUCH): _show_buttons()


func _show_buttons():
    get_node("TouchScreenButton1").show()
    get_node("TouchScreenButton2").show()
    get_node("Timer").start()


func _hide_buttons():
    get_node("TouchScreenButton1").hide()
    get_node("TouchScreenButton2").hide()


func _on_Timer_timeout():
    _hide_buttons()

To test this on a pc, turn on emulate_touchscreen in Project Settings->Display.

Example project download: https://drive.google.com/file/d/0BwnfZQAEnciAWTUxTDh1N2ZrTTA/view?usp=sharing

by (1,302 points)
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.