Buttons on screen

Hello,

I want to add buttons “left”, “right” and “jump” in my game. Put them on the screen, detect touch event and move my player.

is there any tutorial or example game that explain this process?

Thanks in advance

visit this page http://britzl.github.io/publicexamples/ you will find virtual gamepad example there.

2 Likes

Here’s the code for the example: https://github.com/britzl/publicexamples/tree/master/examples/virtual_gamepad and here’s a live example: http://britzl.github.io/publicexamples/virtual_gamepad/index.html

Let me know if you have any questions!

How do i test it in defold editor?

There are detailed instructions here: https://github.com/britzl/publicexamples

thanks, i have installed the example in defold editor and set as initial collection virtual_gamepad example.
i have change the code for button A and B
A: changes the animation of the player
B: set player position to (0,0,0)

i run it in the computer an works ok, because i can’t click 2 buttons at the same time.

If i publish to android phone, when i move the player with the analog direction button, buttons A and B don’t respond

¿is there any way to detect both inputs at the same time?

Ah, good point. You need to enable multi-touch to get that working (and change your on_input function). More details in the input manual: http://www.defold.com/manuals/input/

what do you mean enable multi-touch?
in the game.input_binding i have created a touch_trigger with action called ‘tocar’

in the controls.gui_script in the on_input function i do the following

function on_input(self, action_id, action)
if action_id == hash(“tocar”) and #action.touch<=2 then

is there any example on the web that implements multi touch? for testing in android devices

I’ll see if I have time to create a multi-touch example during the day today. Please bump this post if you don’t see another reply from me this evening.

3 Likes

I already had a simple multi-touch example ready: https://github.com/britzl/publicexamples/tree/examples/multitouch

Note: The example adds a bit of debug output on top of the screen as well since I used it to track down a multi-touch issue we currently have in the engine. If you very rapidly “multi-tap” and release you sometimes lose a “released” even for one of the touch points: Released touch message without pressed touch message (DEF-2024) (SOLVED)

2 Likes

thanks!!! very useful!!

1 Like