Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIBGDX Input - Number of fingers touching the screen

Tags:

android

libgdx

I wonder know How to get the total number of fingers touching the screen on my game.

Thanks you

like image 947
LeSam Avatar asked May 31 '13 06:05

LeSam


3 Answers

If you use an InputProcessor for event-based input processing, just increment a counter at touchDown and decrement the counter at touchUp.

If you're using Gdx.input for polling-based input processing, use the isTouched(int) call to test if pointer N is down. The libGDX implementation tracks at most 20 pointers. I don't think any hardware supports that many (and your game may have a lower limit, too). You'll have to check all the pointer IDs, though, as pointer id N+1 can remain active after pointer id N has left. Something like:

int activeTouch = 0;
for (int i = 0; i < 20; i++) {
    if (Gdx.input.isTouched(i)) activeTouch++;
}
like image 82
P.T. Avatar answered Nov 18 '22 16:11

P.T.


Dont know the proper way of doing it but a nasty and simple method is coming in my mind. Implement inputprocessor reference for input processor here and take a counter variable . Inside its touchdown method increase counter by 1 and inside touchup method decrease counter by 1. the value to counter will give total number of fingures presently touching the screen . Another way to doing it is by pointer in input processor. But I find this method more simpler :)

like image 39
Pranav008 Avatar answered Nov 18 '22 18:11

Pranav008


you can try this:

   float Ipsi=0.5;  
    if(Gdx.input.isTouched()){

        int xTouch = Gdx.input.getX();
        int yTouch = Gdx.input.getY();

        int count=0;
        ArrayList<Integer> lx = new ArrayList<Integer>();
        ArrayList<Integer> ly = new ArrayList<Integer>();

        lx.add(xTouch);
        ly.add(yTouch);


        //lx.size()=ly.size()

        if(2<lx.size()){
                for(int i = 0; i < lx.size(); i++){
                            if((lx.get(i)-lx.get(i+1)<Ipsi)&&(ly.get(i)-ly.get(i+1)<Ipsi))
                            {count++;}
                }
        }



    }

I did not test the code but i hope it will work. good luck.

like image 36
Methnani Bilel Avatar answered Nov 18 '22 16:11

Methnani Bilel