+1 vote

sorry if this is dumb question, but I can't seem to find a solution yet.

I've exported my game on Android, and I can't click multiple buttons at once.
Is there a way to allow multi-touch for TextureButton using its pressed() signal?


in Engine by (28 points)

2 Answers

+3 votes

So for your question first:
No (as far as I know).

A touch on TextureButton generates a pressed() signal but only because of the Touchscreen-Mouse emulation. (If it is enabled in the projects preferences which it is by default.) This Mouse emulation is not multitouch capable. (At least it wasn't the last time, I checked it)

However: You should be able to receive the InputEventScreenTouch Event via the _gui_input() handler. This event has a member pressed which indicates if the area of the control was pressed or released. And it has an index which can be used track different parallel touch events (i.e. when dragging).


Also, there's the TouchScreenButton:

Be aware:
If you have emulations (touch->mouse or mouse->touch) enabled you might receive multiple events on one control at once. (Mouse and Touch)

Finally, there are some touch demos.

by (3,236 points)

I didn't know that there is a TouchScreenButton Node haha. I'll give that one a try first.

What do you mean by emulations is enabled? Is it the one in the project settings, the Emulate Touchscreen - On/Off?

Thanks for this man.

Edit: Hi, I've used _gui_input() as input handler instead of the pressed() signal, just like what you've said and now I am able to do multitouch, Thanks :) but I have another problem though. Multitouch is working and the functions of each pressed can be read but the texture of the buttons doesn't change. The pressed texture is only working on the first button I've pressed, while the other buttons stays normal. (The function for each pressed is still working though)

Did you try setting the buttons pressed attribute when receiving InputEventScreenTouch? (according to pressed state)

Doing it that way maybe can be problematic. I'd see probable problems when a touch is released outside the button. (Finger pressed on button, dragged outside, and then released.) You've got to try this out.

In worst case you'd also have to save the touchevent index for each button on press and watch _input() (which is a global event handler) for pressed=false events with that very index.

Yes, with "Emulations" I'm writing of the project settings->input devices->Pointing.

Emulate Touch from Mouse:
-> Create "fake" Touch events from the Mouse Events. So you can roughly test touch event handling on non-touch devices (on PCs).

Emulate Mouse From Touch:
-> Creates "fake" Mouse events from Touch Events. This enables Mouse-like behaviour on touch-screen devices. But: This emulation is not multi-touch capable. (As far as I know)

Keep in mind:
There's a possibility of mouse events on Mobile Touch-Devices. At least on android devices you can actually attach mice via usb (USB-OTG) or bluetooth.

Yes, I've tried changing to pressed state, but still doesn't work :( the click->drag-> release thing doesn't happen though, well I've made it happen once, I don't know why I can't reproduce it.

This TextureButton is so weird for multitouch hahaha. The function during the pressed state are working fine, but the texture_pressed state is not working.

Ok, I tried around (only on PC using "Emulate Touch Events via Mouse" emulation).

I checked the BaseButton "ToggleMode"
I unchecked ButtonMask (Mouse left), so no Mouse Events trigger the button.
Then I attached this script to the TextureButton:

extends TextureButton
    func _gui_input(event):
        if event is InputEventScreenTouch:
            pressed = !pressed
            print ("pressed: "+str(event.pressed))

Hope this works also on Touch Devices.

–2 votes

on button inspector
on Control>focus>mode choose "click " that for sure will work

i tried it

by (22 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.