Random beginner-question #6: Touch-input triggers multiple times

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

Hi everyone,

I have built a little self-made button (Area2D – CollisionShape2D) including a couple of functions, animations, a timer etc. which all show their “print” in the output. And these work fine when clicking with the mouse, but when thouching the button on a touchscreen some of those “prints” come multiple times, at least twice, sometimes four times…

I can’t quite make out why that happens. Any suggestions?

By the way: testing on a phone obviously doesn’t let me see the output in the editor. Is there a way of displaying that output directly in the running program, like in a text-field? Because I have the feeling that the issue might not appear on all touch-devices generally.

Why not just use a TouchScreenButton node?

rahsut | 2020-08-18 13:06

Hi rahsut,

I tried a TouchScreenButton, to no avail.
It occurs with mouse-clicks as well when I turn on “Emulate Touch From Mouse”, so I feel like it’s probably not a device-issue but indeed my code… I’ll see what I can find out, I just wondered if that might be a known phenomenon in some cases.

pferft | 2020-08-18 13:23

Try calibrating your touch screen. That might help. I have a touchscreen laptop and for me, the touch screen buttons work. Though for me, I’m not printing anything but instead adding a value to my players x value. If calibrating the touch screen still doesn’t fix anything, try using a Button node. That way, you can tell if it’s your code or something else. Also, share some of the code that does the printing. That might help me (and others) better help you .

rahsut | 2020-08-18 21:03

After testing on my touchscreen with an input pen as well, which turned out even more chaotic (triggering three times every now and then…), I’m quite sure it’s not a code-problem.
But I solved the problem with set_pickable:

if Input.is_action_just_pressed("mousebuttonclick"):
	print ("Tapped! Timer started!") # <-- THIS WAS PRINTED 2 TIMES
	get_node("SpriteButtonArea").set_pickable(false)
	get_node("SpriteButtonAnimationPlayer").play("small")
	yield (get_node("SpriteButtonAnimationPlayer"), "animation_finished")
	get_node("SpriteButtonArea").set_pickable(true)

I already did this with all other animations, but for some reason I thought I wouldn’t need to with the extremely short “small” (0.001 sec)… duration obviously doesn’t matter here!

Thanks for your thoughts!

pferft | 2020-08-19 07:57

You can display print messages for an android game by:
(I’m assuming you’ve already set up Godot so it can export games to Android. If not, watch a guide on Youtube or read Godot docs.)

  • click Debug at the top of Godot’s window and make sure “Deploy with remote debug” is checked on.
  • connect your phone to your computer with USB
  • an Android button should appear next to the play scene button, stop scene button, etc. click it to test your game on your phone.
  • output should now print messages on your computer while playing your game on your phone. Yay!

P.S. I’d upload a screenshot but I can’t, and last time I tried setting up imgur, it didn’t work…?

AMixOfGeekStuff | 2021-08-30 21:58

I indeed never checked “remote debug” before and now that I did I wonder why… thanks for the extremely useful hint!

pferft | 2021-09-04 08:33

Np yeah it’s pretty helpful.

AMixOfGeekStuff | 2021-09-04 20:20