I wonder know How to get the total number of fingers touching the screen on my game.
Thanks you
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++;
}
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 :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With