GML Mobile multitouch problem (Videogame Android)

GGJuanPabon

Member
I have the multitouch problem (Videogame Android). There are only 3 buttons, Right, Left and jump. But if I touch right left I can't jump, and if I jump I can't walk, . Did you have a reference video? I searched but did not find a video.

I have the following texts as a reference, but I have tried almost identical, and it does not work, sometimes my character walks and jumps walking, but when I go to jump first, and then walk, it fails.

forum.yoyogames.com/index.php?threads/how-to-enable-multi-touch-for-a-mobile-game.40234/

reddit.com/r/gamemaker/comments/4s0kvz/gml_android_noob_q_how_to_implement_multitouch/

inventati.org/estupidezartificial/web/papers/multitouch.html

I have changed my code several times, I have done things like these.

Tried 1
GML:
for(var i=0; i<2; i++) {
    if (device_mouse_check_button(i, mb_left))
    {
        if (finger[0] < 0)
        {
            finger[0] = i;
        }else
        {
            finger[1] = i;
        }
    }
}

if (device_mouse_check_button(finger[0], mb_left))
    {
    var dMouseX = device_mouse_x_to_gui(finger[0]),
    dMouseY = device_mouse_y_to_gui(finger[0]);           
      
    if    (dMouseX > botonLeftX && dMouseX < botonLeftX + botonsize) &&
        (dMouseY > botonLeftY && dMouseY < botonLeftY + botonsize)       
    {
        global.pressedLeft = true;
        show_debug_message("FINGER 0: " + string(finger[0]));
        show_debug_message("FINGER 1: " + string(finger[1]));
    }else
    {
        global.pressedLeft = false;
        finger[0] = -1
    }

    if    (dMouseX > botonRightX && dMouseX < botonRightX + botonsize) &&
        (dMouseY > botonRightY && dMouseY < botonRightY + botonsize)       
    {
        global.pressedRight = true;
        show_debug_message("FINGER 0: " + string(finger[0]));
        show_debug_message("FINGER 1: " + string(finger[1]));
    }
    else
    {
        global.pressedRight = false;
        finger[0] = -1
    }
}else{
    global.pressedLeft = false;
    global.pressedRight = false;
    finger[0] = -1
}


if (device_mouse_check_button_pressed(finger[1], mb_left))
{
    var dMouseX = device_mouse_x_to_gui(finger[1]),
    dMouseY = device_mouse_y_to_gui(finger[1]);
    if    (dMouseX > botonUpX && dMouseX < botonUpX + botonsize) &&
        (dMouseY > botonUpY && dMouseY < botonUpY + botonsize)       
    {
        global.pressedUp = true;
        show_debug_message("FINGER 0: " + string(finger[0]));
        show_debug_message("FINGER 1: " + string(finger[1]));
    }
    else
    {
        global.pressedUp = false;
    }
}else
    {
        global.pressedUp = false;
        finger[1] = -1
    }
Tried 2
GML:
/// @description Inserte aquí la descripción
// Puede escribir su código en este editor
//show_debug_message(display_get_height());


for(var i=0; i<2; i++)
{
    if (device_mouse_check_button(i, mb_left))
    {
        if (finger[0] < 0)
        {
            finger[0] = i;
            fingerFinal = finger[0];
        }else
        if (finger[1] != i)
        {
            finger[0] = i;
            fingerFinal = finger[0];
        }else
        {
            finger[1] = i;
            fingerFinal = finger[1];
        }
    }
    if (device_mouse_check_button_pressed(i, mb_left))
    {
        if (finger[1] < 0)
        {
            finger[1] = i;
            fingerFinal = finger[1];
        }else
        if (finger[0] != i)
        {
            finger[1] = i;
            fingerFinal = finger[1];
        }else
        {
            finger[0] = i;
            fingerFinal = finger[0];
        }
    }   
}
//==================================== ARROW =======================================//
if (device_mouse_check_button(fingerFinal, mb_left))
{

        var dMouseX = device_mouse_x_to_gui(fingerFinal),
        dMouseY = device_mouse_y_to_gui(fingerFinal);           
      
        if    (dMouseX > botonLeftX && dMouseX < botonLeftX + botonsize) &&
            (dMouseY > botonLeftY && dMouseY < botonLeftY + botonsize)       
        {
            global.pressedLeft = true;
            show_debug_message("FINGER : " + string(fingerFinal));
            show_debug_message("PRESIONANDO a la Izquierda");
        }else
        {
            global.pressedLeft = false;
        }

        if    (dMouseX > botonRightX && dMouseX < botonRightX + botonsize) &&
            (dMouseY > botonRightY && dMouseY < botonRightY + botonsize)       
        {
            global.pressedRight = true;
            show_debug_message("FINGER : " + string(fingerFinal));
            show_debug_message("PRESIONANDO a la Derecha");
        }
        else
        {
            global.pressedRight = false;
        }
        
}else
{
    show_debug_message("FALSOOOOOOOOOOOOO ARROW");
    global.pressedLeft = false;
    global.pressedRight = false;
    finger[0] = -1;
    finger[1] = -1;
}
//==================================== END ARROW =======================================//

if (device_mouse_check_button_pressed(fingerFinal, mb_left))
    {
        show_debug_message("SOLO FUE UN TOQUE");
        var dMouseX = device_mouse_x_to_gui(fingerFinal),
        dMouseY = device_mouse_y_to_gui(fingerFinal);
        if    (dMouseX > botonUpX && dMouseX < botonUpX + botonsize) &&
            (dMouseY > botonUpY && dMouseY < botonUpY + botonsize)       
        {
            global.pressedUp = true;
            show_debug_message("FINGER 0: " + string(fingerFinal));
        }
        else
        {
            global.pressedUp = false;
        }
    }else
    {
        show_debug_message("FALSOOOOOOOOOOOOO JUMP");
        global.pressedUp = false;
        finger[0] = -1;
        finger[1] = -1;
    }
 

samspade

Member
If you want a paid asset that does all of this (mostly) out of the box, I have one.

But in general what you want to do is something like this:
  • loop through touches
  • check collisions
  • note either that there was a collision or more specifically which touch triggered it
GML:
//example

//loop through as many times as you want to check
for (var i = 0; i < number_of_devices; i += 1) {

    //check for each
    if (device_mouse_check_button(i, mb_any)) {
        
        //if a touch is detected, use that touch to check meeting with collision function of choice
        if (place_meeting(device_mouse_x(i), device_mouse_y(i), id)) {
            //do a thing
            //return true
            //return i
            //add i to an array to return all touches it's true for
        }
        
    }
    
}
 

GGJuanPabon

Member
@samspade

Thank you very much for your answer, I will look at your asset, if it is what I need I will not hesitate to buy it, I will also review your fraction of code that you have indicated to me.
 
Top