How to DISABLE the TouchScreenButton ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RockyXDeadman

Hello i am implementing my game touch screen buttons and i have a problem.

i need the button to be disabled for 2 seconds before it can be pressed again but i cannot seem to fix this issue.

i have tried set_block_signals(true) but it did not help.

this is my code. thankyou.

func _on_fire_button_pressed():
      set_block_signals(true)
      $Timer_1.start()                                                                                                                              func _on_Timer_1_timeout():
      set_block_signals(false)

Maybe try set_process_input()?

stan.wick.52 | 2020-11-12 13:26

no i tried it did not work. any idea how i can achieve this?

RockyXDeadman | 2020-11-12 15:53

:bust_in_silhouette: Reply From: Splunk

Well, I guess you could have a bool “can_fire” which is set to false when the button is pressed and set to true when the timer expires. Use this bool to then determine whether the pressing of the fire button results in any action.

yes i tried it too but it did not work for me i dont know why

RockyXDeadman | 2020-11-12 16:22

How about this?

func _on_fire_button_pressed():
	if (can_fire):
		can_fire = false
		$Timer_1.start()
		print("Firing")
	else:
		print("Can't fire yet")
func _on_Timer_1_timeout():
	can_fire = true

Splunk | 2020-11-12 16:41

Or even this to effectively disable the button (get the button mask in the ready function and set it back accordingly):

func _on_fire_button_pressed():
	if ($fire_button.button_mask != 0):
		$fire_button.button_mask = 0;
		$Timer_1.start()
		print("Firing")

func _on_Timer_1_timeout():
	$fire_button.button_mask = 1;

Splunk | 2020-11-12 16:46

thanks a lot. i fixed my problem my way. maybe in future your solution will be useful for someone. thankyou.

RockyXDeadman | 2020-11-12 17:23

:bust_in_silhouette: Reply From: RockyXDeadman

for future reference i fixed it this way :

func _on_fire_touch_pressed():
	$fire_touch.action = "nothing"                                                              
    $fire_touch.visible = false
	yield(get_tree().create_timer(2),"timeout")
	$fire_touch.visible = true
	$fire_touch.action = "fire"

in input_mapping make a nothing button which does nothing and use it in here. like shown above.

Nice. This will come in handy

stan.wick.52 | 2020-11-14 22:31