Following Mouse with Multi-Touch

D

Desperado

Guest
Target: Android

Game is coded for multi-touch.

The base of the code below was posted by GameGoblin in the old Forum

My issue:

I have two objects, Button and Player.
The player and button move just on its Y axes.
The Player object follows the Button

The Button is controlled by the person playing the game. (I am setting it up this way so you don’t cover your player with your finger and to give the person playing a sense of where they should touch the screen to move their player object.)

I can get this to work with a few different methods without multi-touch, but not with multi-touch.
I have blinders on, now that I have focused so long on one set codes.

Below is the code that works if I give it a device number, but doesn’t work of course with my multi-touch method (using a for loop to cycle device number)

When I add the “for loop” to the code and run it. The button object disappears has soon has I touch it.
I am missing something, still new to coding. I am guessing to many "if" statements in my "for loop" .
Please help with some direction.

BUTTON Object
Create:

dragging = false;
my = -1;


Step:
for (i=0; i<4; i+=1)
{
if (dragging)
{
y = device_mouse_y(i) + my;
}​

if (!device_mouse_check_button((i),mb_left))
{
dragging = false;
}​

else if (device_mouse_check_button((i),mb_left)) && position_meeting(device_mouse_x(i), device_mouse_y(i), id)
{
dragging = true;
my = y - device_mouse_y(i);​
}​

}
 

johnwo

Member
Try this:

Code:
for (i=0; i<4; i+=1) {
    if (dragging) {
        y = device_mouse_y(i) + my;
        
        if (!device_mouse_check_button((i),mb_left)) {
            dragging = false;
        }
    }

   
     if (device_mouse_check_button((i),mb_left)) && position_meeting(device_mouse_x(i), device_mouse_y(i), id) {
         dragging = true;
         my = y - device_mouse_y(i);
     }

}
Should that not work, and you don't use a dynamic view. try:
Code:
for (i=0; i<4; i+=1) {
    if (dragging) {
        y = device_mouse_y(i);
        
        if (!device_mouse_check_button((i),mb_left)) {
            dragging = false;
        }
    }

   
     if (device_mouse_check_button((i),mb_left)) && position_meeting(device_mouse_x(i), device_mouse_y(i), id) {
         dragging = true;
         y = device_mouse_y(i);
     }
}
Let me know how it works out!

Cheers!
 
D

Desperado

Guest
No go johnwo,

Neither one of them worked.

I will keep trying, thanks
 
Top