Asset - Extension Simple Multitouch

samspade

Member
Available for GMS 2

Description


An extension to make working with multiple touches easy! While the built-in Gesture Events are suitable for many purposes, this extension fills in the gaps or simply gives you greater control. Import the extension and gain access to all the functions.

Heavily documented and easily extendable, the extension contains the following functions:

General Functions
  • set_device_amount
  • touch_x
  • touch_y
  • touch_x_gui
  • touch_y_gui
  • device_meeting
  • device_meeting_gui
  • collect_touches
  • collect_presses
  • collect_releases
  • collect_meetings
  • collect_meetings_gui
Touch Detection
  • touch_check
  • touch_check_any
  • touch_check_all
  • touch_check_pressed
  • touch_check_pressed_any
  • touch_check_pressed_all
  • touch_check_released
  • touch_check_released_any
  • touch_check_released_all
Collision Detection
  • touch_meeting
  • touch_meeting_any
  • touch_meeting_all
  • touch_meeting_pressed
  • touch_meeting_pressed_any
  • touch_meeting_pressed_all
  • touch_meeting_released
  • touch_meeting_released_any
  • touch_meeting_released_all
GUI Collision Detection
  • touch_meeting_gui
  • touch_meeting_any_gui
  • touch_meeting_all_gui
  • touch_meeting_pressed_gui
  • touch_meeting_pressed_any_gui
  • touch_meeting_pressed_all_gui
  • touch_meeting_released_gui
  • touch_meeting_released_any_gui
  • touch_meeting_released_all_gui

Important notes:

  • This asset also comes with a small demo project for example purposes.
  • Read the README for instructions on using, importing, and extending the functions in this asset!
  • This extension is only useful for devices that accept multiple touches.
  • Contact me with questions as I will provide continuing support.
 
E

ElViejoSanta

Guest
HI! I just bought the extension but I can´t figure out how to make it work. I've never worked with extensions before.
In my project I'm trying to use a virtual stick for movement (wich is made out of device_mouse_check) and other buttons (which are virtual keys). When I use the analog first and then the buttons it works just fine, but when I use the buttons first (like a shield button which is set to keyboard_check) and then the analog I can´t get it to work.

I´m sorry for this, It may be very simple but I can´t figure it out by myself.
Thanks in advance!
 

samspade

Member
HI! I just bought the extension but I can´t figure out how to make it work. I've never worked with extensions before.
In my project I'm trying to use a virtual stick for movement (wich is made out of device_mouse_check) and other buttons (which are virtual keys). When I use the analog first and then the buttons it works just fine, but when I use the buttons first (like a shield button which is set to keyboard_check) and then the analog I can´t get it to work.

I´m sorry for this, It may be very simple but I can´t figure it out by myself.
Thanks in advance!
Thanks for purchasing it. Extension functions work, essentially, exactly like the built in functions inside of game maker, you can look at the code in one of the notes or by opening the file and checking the extension folder (more description in the readme file).

I can't answer it off the top of my head, as I don't know what the rest of your project looks like, but If you want, contact me through my support email, I'd be happy to look at the project for you.

A example which might work (again heavy emphasis on might not knowing the rest of your code) would be something like this where my_touch is set to -1 in the create event and the joystick is an object with a sprite and a collision mask:

Code:
//check for any touches, and if there is a touch, get all and assign the first as the touch to track
if (touch_meeting_pressed_any(id)) {
    var touch_array = touch_meeting_pressed_all(id);
    my_touch = touch_array[0];
}

//check to see if that touch is released, and if so set my_touch to -1
if (touch_check_released(touch, mb_any)) {
    my_touch = -1;
}

//now you know the touch to track and can use it
if (my_touch != -1) {
    //do whatever it is you do to move the joystick
}
(note that this code could be better, and more concise, this is just an example of the basic idea you would use)
 
Last edited:
E

ElViejoSanta

Guest
Thank you very much for your fast answer. Unfortunately I still can't get it to work. Here's the code:

Code:
//Create
stick_X=320;
stick_Y=760;
stick_on=false;
stick_mx=0;
stick_my=0;
stick_rad=sprite_get_width(spr_vstick)/2;
my_touch=0; //This is just set to 0 because It doesn't work propperly in any case.

//Step
if device_mouse_check_button(my_touch,mb_left)
    {
        var mx=device_mouse_x_to_gui(my_touch),
              my=device_mouse_y_to_gui(my_touch);
        if !stick_on
        {
        if (mx <= display_get_gui_width()/2 && my>=display_get_gui_height()/2)
            {
            stick_X=mx;
            stick_Y=my;
            stick_on=true;
            }
      
        }
        else
        {
            var angle=point_direction(stick_X,stick_Y,mx,my),
                distance=point_distance(stick_X,stick_Y,mx,my);
  
            stick_mx=dcos(angle)* min(stick_rad,distance);
            stick_my=-dsin(angle)* min(stick_rad,distance);
        }
    }
    else
    {
    stick_on=false;
    stick_mx=0;
    stick_my=0;
    }
Thanks again!!!
 

samspade

Member
Thank you very much for your fast answer. Unfortunately I still can't get it to work. Here's the code:

Code:
//Create
stick_X=320;
stick_Y=760;
stick_on=false;
stick_mx=0;
stick_my=0;
stick_rad=sprite_get_width(spr_vstick)/2;
my_touch=0; //This is just set to 0 because It doesn't work propperly in any case.

//Step
if device_mouse_check_button(my_touch,mb_left)
    {
        var mx=device_mouse_x_to_gui(my_touch),
              my=device_mouse_y_to_gui(my_touch);
        if !stick_on
        {
        if (mx <= display_get_gui_width()/2 && my>=display_get_gui_height()/2)
            {
            stick_X=mx;
            stick_Y=my;
            stick_on=true;
            }
     
        }
        else
        {
            var angle=point_direction(stick_X,stick_Y,mx,my),
                distance=point_distance(stick_X,stick_Y,mx,my);
 
            stick_mx=dcos(angle)* min(stick_rad,distance);
            stick_my=-dsin(angle)* min(stick_rad,distance);
        }
    }
    else
    {
    stick_on=false;
    stick_mx=0;
    stick_my=0;
    }
Thanks again!!!
I see a couple problems here. First, you're not actually using any of the functions in the extension. You're using the built in functions. Second, you can't set my_touch to 0 as that is a valid device number - it generally corresponds to the mouse or first touch - so your code, while valid, will only work for one touch - the first one. The whole point of the extension is to allow multiple touches. Try using the code I provided above to get the right touch and then using that touch's position. For something like this, I'd be willing to take a look at the stripped down project (e.g. just a room with the virtual stick and keys) if you wanted to send it to my support email: [email protected].
 
E

ElViejoSanta

Guest
I see a couple problems here. First, you're not actually using any of the functions in the extension. You're using the built in functions. Second, you can't set my_touch to 0 as that is a valid device number - it generally corresponds to the mouse or first touch - so your code, while valid, will only work for one touch - the first one. The whole point of the extension is to allow multiple touches. Try using the code I provided above to get the right touch and then using that touch's position. For something like this, I'd be willing to take a look at the stripped down project (e.g. just a room with the virtual stick and keys) if you wanted to send it to my support email: [email protected].
I know that it's no use of the extension in the code, I just reverted the code back to when I wasn't using it to see how it should be implemented. My bad. I'm sending you the project anyway, I would love to have this virtual stick working properly. Thank you very much.
 
Top