• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM Multi-touch issues

Sk8dududu

Member
I just recently added multi touch for a game that I'm making for my 2 year old daughter to her learn her abc's.
Multi-touch is pretty important because my phone is almost 100% screen so her holding it registers as a touch and wont be able to tap anything else.
It's a simple bubble game where you pop bubbles to reveal a letter which then plays an audio clip of the letter, shows a picture and says an audio clip of the picture. And then restarts to show a random letter again. (She loves bubbles, its her favourite word).

I've come across two issues that I didn't have before adding a second touch.
1: The mask for the objects has become huge, I have the collision mask set up to be only the bubble, but now it extends to about double the width for seemingly no reason.
2: The very last bubble becomes untappable. It will not pop, with either device0 or device1, (tap1 and tap2)
Another thing that has changed that I actually like is it only pops the bubble that is on the top layer which I found very odd but it's a nice feature.

I only have 2 objects, the controller and the bubble, I cannot for the life of my find out why the last bubble wont pop.

Controller step event
Code:
if !instance_exists(obj_bubble) and sound = false
    {
    sound = true;
    switch(letter)
        {
        case 1: audio_play_sound(sound_a,1,false); break;
        case 2: audio_play_sound(sound_b,1,false); break;
        etc..
        }
    }
Bubble create event
Code:
///Variables
image_speed = 0;
sprite_index = choose(spr_bubble1,spr_bubble2);
image_xscale = random_range(0.50,1);
image_yscale = image_xscale;
depth = - 10;
Bubble step event
Code:
///Pop
//Touch one
if device_mouse_check_button_pressed(0,mb_left) == true
    {
    if place_meeting(device_mouse_x(0),device_mouse_y(0),obj_bubble) == true
        {
        with instance_place(device_mouse_x(0),device_mouse_y(0),obj_bubble)
            {
            image_speed = 0.35;
            if global.pop = false
                {
                global.pop = true;
                audio_play_sound(sound_bubble_pop,1,false);
                }
            }
        }
    }
//Touch two
if device_mouse_check_button_pressed(1,mb_left) == true
    {
    if place_meeting(device_mouse_x(1),device_mouse_y(1),obj_bubble) == true
        {
        with instance_place(device_mouse_x(1),device_mouse_y(1),obj_bubble)
            {
            image_speed = 0.25;
            if global.pop = false
                {
                global.pop = true;
                audio_play_sound(sound_bubble_pop,1,false);
                }
            }
        }
    }
Bubble animation end event
Code:
///Destroy
global.pop = false;
instance_destroy();
Anyone notice why this all broke from adding a second device?
 

Timothy

Member
I just recently added multi touch for a game that I'm making for my 2 year old daughter to her learn her abc's.
Multi-touch is pretty important because my phone is almost 100% screen so her holding it registers as a touch and wont be able to tap anything else.
It's a simple bubble game where you pop bubbles to reveal a letter which then plays an audio clip of the letter, shows a picture and says an audio clip of the picture. And then restarts to show a random letter again. (She loves bubbles, its her favourite word).

I've come across two issues that I didn't have before adding a second touch.
1: The mask for the objects has become huge, I have the collision mask set up to be only the bubble, but now it extends to about double the width for seemingly no reason.
2: The very last bubble becomes untappable. It will not pop, with either device0 or device1, (tap1 and tap2)
Another thing that has changed that I actually like is it only pops the bubble that is on the top layer which I found very odd but it's a nice feature.

I only have 2 objects, the controller and the bubble, I cannot for the life of my find out why the last bubble wont pop.

Controller step event
Code:
if !instance_exists(obj_bubble) and sound = false
    {
    sound = true;
    switch(letter)
        {
        case 1: audio_play_sound(sound_a,1,false); break;
        case 2: audio_play_sound(sound_b,1,false); break;
        etc..
        }
    }
Bubble create event
Code:
///Variables
image_speed = 0;
sprite_index = choose(spr_bubble1,spr_bubble2);
image_xscale = random_range(0.50,1);
image_yscale = image_xscale;
depth = - 10;
Bubble step event
Code:
///Pop
//Touch one
if device_mouse_check_button_pressed(0,mb_left) == true
    {
    if place_meeting(device_mouse_x(0),device_mouse_y(0),obj_bubble) == true
        {
        with instance_place(device_mouse_x(0),device_mouse_y(0),obj_bubble)
            {
            image_speed = 0.35;
            if global.pop = false
                {
                global.pop = true;
                audio_play_sound(sound_bubble_pop,1,false);
                }
            }
        }
    }
//Touch two
if device_mouse_check_button_pressed(1,mb_left) == true
    {
    if place_meeting(device_mouse_x(1),device_mouse_y(1),obj_bubble) == true
        {
        with instance_place(device_mouse_x(1),device_mouse_y(1),obj_bubble)
            {
            image_speed = 0.25;
            if global.pop = false
                {
                global.pop = true;
                audio_play_sound(sound_bubble_pop,1,false);
                }
            }
        }
    }
Bubble animation end event
Code:
///Destroy
global.pop = false;
instance_destroy();
Anyone notice why this all broke from adding a second device?
Your bubbles step is funky... i would just trash that to be honest and do the touch check in the controllers step event. Try this out (support up to 5 touches)
Code:
if (!global.pop)
{
    for (var i = 5; i >= 0; --i)
    {
       if (device_mouse_check_button_pressed(i, mb_left))
       {
           var bub = instance_position(device_mouse_x(i), device_mouse_y(i), obj_bubble);
           if (bub != noone)
           {
               bub.image_speed = 0.25;
               global.pop = true;
               audio_play_sound(sound_bubble_pop, 1, false);
               break;
           }
       }
   }
}
 

samspade

Member
If this is all the code is, I would use the gesture event. They detect multiple touches automatically and there doesn't seem to be any particularly reason not to use them here. That would turn all of your bubble step event code into:

Code:
image_speed = 0.35;
if (global.pop == false) {
    global.pop = true;
    audio_play_sound(sound_bubble_pop, 1, false);
}
However, I don't see a problem with your code. But that also doesn't look like all of it.

As to why it is only picking the bubble on top, that is essentially a fluke of your code. Your code doesn't check whether or not you are clicking on that bubble. It only checks whether or not you are clicking on any bubble then it picks essentially at random. Or rather, in an order determined by GM based upon the specifics of the platform and other internal workings. In practice its often creation order, which is also used to determine drawing when things are on the same layer. It just so happens that in your case, that means the top instance. This is unlikely to be consistent across platforms or updates and shouldn't be relied on to produce that effect (though it doesn't seem like it is that important here).

Edit: I didn't see that this was GMS 1. I don't think GMS 1 has gesture events, so you'll have to do it manually. As Timothy said, in that case I would do it from a primary controller object.
 

Sk8dududu

Member
Your bubbles step is funky... i would just trash that to be honest and do the touch check in the controllers step event. Try this out (support up to 5 touches)
Code:
if (!global.pop)
{
    for (var i = 5; i >= 0; --i)
    {
       if (device_mouse_check_button_pressed(i, mb_left))
       {
           var bub = instance_position(device_mouse_x(i), device_mouse_y(i), obj_bubble);
           if (bub != noone)
           {
               bub.image_speed = 0.25;
               global.pop = true;
               audio_play_sound(sound_bubble_pop, 1, false);
               break;
           }
       }
   }
}
Yeah I've never done multi touch before so I just winged it. Lol
You're works perfectly and it still retains only popping the 1 bubble on the very top layer first. I really appreciate your help.
 

Sk8dududu

Member
If this is all the code is, I would use the gesture event. They detect multiple touches automatically and there doesn't seem to be any particularly reason not to use them here. That would turn all of your bubble step event code into:

Code:
image_speed = 0.35;
if (global.pop == false) {
    global.pop = true;
    audio_play_sound(sound_bubble_pop, 1, false);
}
However, I don't see a problem with your code. But that also doesn't look like all of it.

As to why it is only picking the bubble on top, that is essentially a fluke of your code. Your code doesn't check whether or not you are clicking on that bubble. It only checks whether or not you are clicking on any bubble then it picks essentially at random. Or rather, in an order determined by GM based upon the specifics of the platform and other internal workings. In practice its often creation order, which is also used to determine drawing when things are on the same layer. It just so happens that in your case, that means the top instance. This is unlikely to be consistent across platforms or updates and shouldn't be relied on to produce that effect (though it doesn't seem like it is that important here).

Edit: I didn't see that this was GMS 1. I don't think GMS 1 has gesture events, so you'll have to do it manually. As Timothy said, in that case I would do it from a primary controller object.
Yeah unfortunately don't have gms2 because I don't wanna get all of the export modules again. :(
Gesture events sure would have been nice when I was adding swipe controllers. Lol
Not all of the code but it's all of the relevant code other than just drawing stuff and playing sounds.
I got it to work though with Tim's code. Gm just didn't like my spaghetti mess in that bubble step event.
 

Timothy

Member
Yeah I've never done multi touch before so I just winged it. Lol
You're works perfectly and it still retains only popping the 1 bubble on the very top layer first. I really appreciate your help.
No problem, though it popping the top layer first is likely undependable because I do not think that instance_position does any sort of depth check.
 
Top