Problem making touch pads

Status
Not open for further replies.
J

Jeuiop

Guest
Code:
//STEP EVENT

x = view_xview + 50;
y = view_yview + 260;   */
positionFireX = view_xview + 430;
positionFireY = view_yview + 260;

positionMoveX = view_xview + 50;
positionMoveY = view_yview + 260;

mx0 = device_mouse_x(0);
my0 = device_mouse_y(0);
mx1 = device_mouse_x(1);
my1 = device_mouse_y(1);


//--------------POSITION---------------

if(device_mouse_check_button(0, mb_left) or device_mouse_check_button(1, mb_left)){

if( (mx0 < (positionMoveX + 64) and mx0 > (positionMoveX - 64)) and (my0 > (positionMoveY - 64) and my0 < (positionMoveY + 64))){
   
    global.isPressedMove = true;
   
    xCoord0 = mx0;
    yCoord0 = my0;
   
} else if((mx1 < (positionMoveX + 64) and mx1 > (positionMoveX - 64)) and (my1 > (positionMoveY - 64) and my1 < (positionMoveY + 64))){
   
    global.isPressedMove = true;
   
    xCoord0 = mx1;
    yCoord0 = my1;
   
} else {
    global.isPressedMove = false;
}
   
if( (mx0 < (positionFireX + 64) and mx0 > (positionFireX - 64)) and (my0 > (positionFireY - 64) and my0 < (positionFireY + 64))){
   
    global.isPressedFire = true;
   
    xCoord1 = mx0;
    yCoord1 = my0;
   
} else if((mx1 < (positionFireX + 64) and mx1 > (positionFireX - 64)) and (my1 > (positionFireY - 64) and my1 < (positionFireY + 64))){
   
    global.isPressedFire = true;
   
    xCoord1 = mx1;
    yCoord1 = my1;
   
} else {
    global.isPressedFire = false;
}
   
} else {global.isPressedFire = false; global.isPressedMove = false;}

if(global.isPressedMove){
    dirMove = point_direction(positionMoveX, positionMoveY, xCoord0, yCoord0);
    if(instance_exists(oPlayer)) oPlayer.dir = dirMove;
    if(point_distance(positionMoveX, positionMoveY, xCoord0, yCoord0) < 48){
        stickX1 = xCoord0;
        stickY1 = yCoord0;
    } else {

        stickX1 = positionMoveX + lengthdir_x(48, dirMove);
        stickY1 = positionMoveY + lengthdir_y(48, dirMove);
    }
} else {
   
    dirMove = noone;
    stickX1 = positionMoveX;
    stickY1 = positionMoveY;
    global.isPressedMove = false;
   
}

if(global.isPressedFire){
    dirFire = point_direction(positionFireX, positionFireY, xCoord1, yCoord1);
    if(instance_exists(oPlayer))  oWeapon.dir = dirFire;
    if(point_distance(positionFireX, positionFireY, xCoord1, yCoord1) < 48){
        stickX = xCoord1;
        stickY = yCoord1;
    } else {

        stickX = positionFireX + lengthdir_x(48, dirFire);
        stickY = positionFireY + lengthdir_y(48, dirFire);
    }
} else {
   
    dirFire = noone;
    stickX = positionFireX;
    stickY = positionFireY;
    global.isPressedFire = false;
}
So, i've been working on touch pads these few past days, and i almost make it work completely free bug but get an error i can't solve.

The bug is that when i press both pads at the same time and then release one of them, the other seems to keeps activating and i don't know why. One of the pads is supposed to move the player and other aim to shoot.

Here is the whole code for the pads.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You are checking both mx/my0 and mx/my1 for both movement and firing. You need to do this differently... don't hardcode the devices numbers like this and instead use a for loop to find out which fingers are actually being used and then check each finger once... you can simply check to see if the touch is left of the display center ot right of the display center to find out if it is a shoot or a move, and then deal with it accordingly.
 
C

Cam5179

Guest
I know this is an old thread but for your controls were you using a touch pad separate from your game like a game pad or was the game on the device because i havent found any way to make a seperate touch device a game pad and was wondering if its even possible
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I know this is an old thread but for your controls were you using a touch pad separate from your game like a game pad or was the game on the device because i havent found any way to make a seperate touch device a game pad and was wondering if its even possible
Make a new topic please and don't bump topics that have been dead for nearly a year... You'll get more (and better) replies with a new topic. ;)
 
Status
Not open for further replies.
Top