Java – how do I detect the number of fingers in use?

I'm playing a game with libgdx. I need to know if the user is using two fingers and placing them in the right position One finger should be on the right side of the screen and the other finger should be on the left side of the screen

Solution

The simplest solution without any listeners is to iterate over some pointer counts and call the simple GDx input. Istouched () – you have to set some "maximum pointer count", but hey – people usually have only 20 fingers:)

final int MAX_NUMBER_OF_POINTERS = 20;
    int pointers = 0;

    for(int i = 0; i < MAX_NUMBER_OF_POINTERS; i++)
    {  
        if( Gdx.input.isTouched(i) ) pointers++;
    }

    System.out.println( pointers );

Due to reference:

You can also use GDx input. GeTx () and GDx input. Gety () to easily touch the position of the pointer

final int MAX_NUMBER_OF_POINTERS = 20;
    int pointers = 0;

    for(int i = 0; i < MAX_NUMBER_OF_POINTERS; i++)
    {  
        if( Gdx.input.isTouched(i) )
        {
            x = Gdx.input.getX(i);
            y = Gdx.input.getY(i)
        }
    }

Then you can put it in the array

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>