• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Android Multitouch capabilites problem

G

Gunslito

Guest
Hi guys, I've a problem with my game.

I'm using this code on step event of btn_left:

for(var i=0; i<4; i++)
{
if (device_mouse_check_button_pressed(i,mb_left) && position_meeting(device_mouse_x_to_gui(i),device_mouse_y_to_gui(i),btn_left))
{
Pressed=1
Image_index=1
Birdie.keyleft=-1
}
else Pressed=0;Image_index=0; Birdie.keyleft=0
}
(The sprites are drawn into the Draw Gui event)
when I press it "Birdie" walks to the left, but if I release the button it stills keep walking, the same happens with Jump, the object is coded like this:
If I maintain jump it'll jump higher, but when I use this on Android it keeps jumping all the time and the jumps are short, I need to press anywhere on the screen to cancel any button press.
I'm so sorry for my bad english
 

2Dcube

Member
You're checking for 4 touch events (4 fingers) every frame. Unless all 4 are touching the button, you will always trigger the "else" part, since at least one of the 4 fingers will not touch the button.
If I understand your code correctly...

What if you first check if one of the 4 fingers is touching, and then after checking perform any changes. Like so:
Code:
Pressed=0

for(var i=0; i<4; i++)
{
if (device_mouse_check_button_pressed(i,mb_left) && position_meeting(device_mouse_x_to_gui(i),device_mouse_y_to_gui(i),btn_left))
{
Pressed=1
break // you can break the loop here since you know 1 of the 4 fingers has pressed the button
}
}

if Pressed
{
  // do stuff that needs to happen if the button is pressed
}
else
{
  // do stuff that needs to happen if the button is not pressed
}
 
G

Gunslito

Guest
First of all thank you a lot for taking your time to help me.
I have this code now on btn_left object:
Create event:
image_speed=0
Pressed=0
image_index=Pressed

Step Event:
for(var i=0; i<4; i++)
{
if (device_mouse_check_button_pressed(i,mb_any) && position_meeting(device_mouse_x_to_gui(i),device_mouse_y_to_gui(i),btn_left))
{
Pressed=1
break // you can break the loop here since you know 1 of the 4 fingers has pressed the button
}
}

if Pressed==1
{
image_index=1
Birdie.keyleft=-1
}
else
{
Pressed=0
image_index=0
Birdie.keyleft=0
}

But neither if I press the button the image doesn't change and if I release it the player keeps moving, only if I touch elsewhere it stops.
 

2Dcube

Member
Are you sure you're pressing the button?
The actual position of the instance "btn_left" could be different from where it's drawn in the GUI. The GUI layer can have a different scale compared to the game world.
To check, you could draw "btn_left" in the regular Draw Event to see if there's a difference with the Draw GUI Event.
And use
Code:
position_meeting(mouse_x, mouse_y, btn_left))
to click on it.
 
G

Gunslito

Guest
I can touch the button on android, if I use mouse_x and mouse_y the multitouch capabilities will be gone and I need that. The thing is when I release the finger from the button it keeps pushing until I touch elsewhere on the screen of the device
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
position_meeting requires a mask for the instance doing the checking, so I would think you really want to use instance_position... Apart from that, nowhere in the code do you show the instance being moved, and if the issue is that the instance keeps moving then I would say it's important to know how you are moving it. ;)
 
Top