Android [SOLVED] Touchscreen: Two players touching same screen simultaneously?

A

Adam Martinez

Guest
Hello!

For an Android game, I'm looking for a solution in which two players can simultaneously touch and drag objects on the same screen with one device. I did some research and I saw that many "simultaneous" two-player one-device games really work with alternating touch.

I want two players to grab "worms" from the play field and pull them toward opposite sides of the screen to "feed baby birds". Is this possible on one device?

Thank you!
 

PNelly

Member
Yeah sure. When two fingers are touching the screen at once, GameMaker interprets that as a right mouse click at the location of the second finger. Read the manual.
 
A

Adam Martinez

Guest
Yeah sure. When two fingers are touching the screen at once, GameMaker interprets that as a right mouse click at the location of the second finger. Read the manual.
Nice! Thank you!
 
A

Adam Martinez

Guest
Here is the solution I worked out to allow up to five touch inputs on one device simultaneously. In my example, I only use two inputs.

Here is related documentation. https://docs.yoyogames.com/source/d...rd and other controls/device input/index.html

I hope this is useful to someone else later on. Thanks again PNelly for for the quick reply!

obj_mouse_0


Create
hand_full = false

Step
if device_mouse_check_button(0, mb_left) = true {
x = device_mouse_x(0)
y = device_mouse_y(0)​
}

obj_mouse_1

Create
hand_full = false

Step
if device_mouse_check_button(1, mb_left) = true {
x = device_mouse_x(1)
y = device_mouse_y(1)​
}

obj_object_to_touch_and_move

Create
x_diff_0 = 0
y_diff_0 = 0
x_diff_1 = 0
y_diff_1 = 0
grabbed_0 = false
grabbed_1 = false

Step

//The difference in position between the object to be moved and the touch input is stored, by device. This is so you can "grab" objects on-screen from anywhere on the object, and the motion of the grabbed object can stay relative to the motion of the player's finger, instead of jumping to some position directly under the player's finger.

if grabbed_0 = false {
x_diff_0 = obj_mouse_0.x - x
y_diff_0 = obj_mouse_0.y - y
}

if grabbed_1 = false {
x_diff_1 = obj_mouse_1.x - x
y_diff_1 = obj_mouse_1.y - y
}

//Objects the player touches are "grabbed", and these objects follow the player's finger as long as the screen is touched.

if place_meeting(x,y,obj_mouse_0)
&& device_mouse_check_button(0, mb_left) = true
&& grabbed_0 = false
&& obj_mouse_0.hand_full = false
&& grabbed_1 = false {
grabbed_0 = true
obj_mouse_0.hand_full = true
audio_play_sound(sfx_grab, 1, false)
}

if place_meeting(x,y,obj_mouse_1)
&& device_mouse_check_button(1, mb_left) = true
&& grabbed_1 = false
&& obj_mouse_1.hand_full = false
&& grabbed_0 = false {
grabbed_1 = true
obj_mouse_1.hand_full = true
audio_play_sound(sfx_grab, 1, false)
}

if grabbed_0 = true
&& (obj_mouse_0.x != -100)
&& (obj_mouse_0.y != -100) {
x = obj_mouse_0.x - x_diff_0
y = obj_mouse_0.y - y_diff_0
}

if grabbed_1 = true
&& (obj_mouse_1.x != -100)
&& (obj_mouse_1.y != -100) {
x = obj_mouse_1.x - x_diff_1
y = obj_mouse_1.y - y_diff_1
}

//"Grabbed" objects are "let go" when the player lifts his or her finger off the screen. The "mouse" object is then moved to some arbitrary position out of the view (-100, -100) until the player touches the screen again at some different position. (I believe) This is necessary, or no matter where the player touches next, the last object "let go" will be "grabbed" again because the position of the device cursor doesn't move or disappear just because the player stops touching the screen.

if device_mouse_check_button(0, mb_left) = false {
grabbed_0 = false
obj_mouse_0.hand_full = false
if obj_mouse_0.x != -100
&& obj_mouse_0.y != -100 {
audio_play_sound(sfx_drop, 1, false)
}
obj_mouse_0.x = -100
obj_mouse_0.y = -100
}

if device_mouse_check_button(1, mb_left) = false {
grabbed_1 = false
obj_mouse_1.hand_full = false
if obj_mouse_1.x != -100
&& obj_mouse_1.y != -100 {
audio_play_sound(sfx_drop, 1, false)
}
obj_mouse_1.x = -100
obj_mouse_1.y = -100
}
 
Top