Android Problem with the Multi Touch

A

ArtCode

Guest
Hello to everyone,
I'm making a little arcade game on Android and I want to implement a multi touch movement.
Something like Microtrip. Examle:

If I press the left side of the screen -> The player moves to the left
If I press the right side of the screen -> The player moves to the right
and this is OK!
The problem starts while I press the the screen when a finger is already pressing...
While I'm pressing the LEFT side and then I touch the RIGHT side the PLAYER just STOPS...
I want to give the priority to the LAST finger pressed... somehow to disable the touch used before.
Here is my code:
Player STEP EVENT
Code:
device_mouse_dbclick_enable(true);

if (point_distance(x, y, mouse_x, obj_Player.y) > 5) && (mouse_check_button(mb_left)) {
   move_towards_point(mouse_x, obj_Player.y, 5);
    if(mouse_check_button(mb_right)){
        move_towards_point(mouse_x, obj_Player.y, 5); 
   }   
}
else speed = 0;
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Why are you enabling RMB double click? This is NOT what you want to do as it turns a double tap into he RMB. So for your game to work it will require the player to tap the right of the screen twice before the movement will be detected. Apart from that, your code should look like this:

Code:
//Check for a touch
if device_mouse_check_button(0, mb_left)
    {
    // Check if touch is to the left or the right and move player accordingly
    var _xx = device_mouse_x_to_gui(0);
    if _xx < display_get_gui_width() / 2
        {
        x -= 5;
        }
    else x += 5;
    break;
    }
 
A

ArtCode

Guest
Ohhh... so the RMB double click was absolutely not good for what I thought... thanks a lot for your code and your tip!
Just tried it and the base concept works! If I touch the LEFT or RIGHT side of the screen the player moves in that position! :)
But it haves a little problem... If I press the RIGHT side of the screen slightly before releasing the LEFT side (or vice versa) the player stops! It's not recognizing the last side touched...
I just deleted the BREAK; line code because it was giving me an error, but I dont think that was the problem ...
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
So, you want the last touch to override the first touch? In that case:

Code:
// Some local vars to control which is the last pressed
var _leftpressed = false;
var _rightpressed = false;
// Loop through all "fingers" to detect a touch
for (var i = 0; i < 5; i++;)
{
if device_mouse_check_button(i, mb_left)
    {
    var _xx = device_mouse_x_to_gui(i);
    // Set local vars based on left/right touch
    if _xx < display_get_gui_width() / 2
        {
        _leftpressed = true;
        _rightpressed = false;
        }
    else
        {
        _leftpressed = false;
        _rightpressed = true;
        }
    break;
    }
}
// Move the player only left or only right...
if _leftpressed x -= 5;
if _rightpressed x += 5;
Hope that helps!
 
Last edited:
A

ArtCode

Guest
Wow thanks again for your time! I really appreciate it :)
I tried the code but now it haves another kind of BUG, now If I press the RIGHT side of the screen slightly before releasing the LEFT (or vice versa) the player continues to MOVE! but to his last direction, not in the opposite one :(
So if I press the RIGHT side and then I touch the LEFT side, the player continues to move to the RIGHT direction....
@Nocturne you already gave me enough help and good tips on what I must focus, I'll try to fix the code. If I wont be able to solve this I'll search you again ahahah :D
Thanks a lot again!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I made a minor mistake with the code above... So re-copy/paste it as I've edited it to fix the mistake and let me know if that fixes the error... ;)
 
A

ArtCode

Guest
I made a minor mistake with the code above... So re-copy/paste it as I've edited it to fix the mistake and let me know if that fixes the error... ;)
WOOOOO!!!! Works very very well!!! Thanks a lot Nocturne :) this code really helped me! Thanks again and have a good day!
 
Top