问题
I need a way to tell if there is at least one finger touching the screen. I had no problem doing this in LibGDX but now I can't do it without it. This is how I have it setup:
public static boolean screenTouched = false;
//This methods is run at 60FPS by the main thread (it's the main game loop)
public static void update(){
//Run other updates...
screenTouched = false;//Called after other updates
}
public boolean onTouchEvent(MotionEvent e){
screenTouched = true;
}
By the way, this is all in the main activity class.
This seems like it would work fine, right? It doesn't, onTouchEvent(MotionEvent e)
is only called by android when the user's finger moves on the screen and doesn't care about whether they are just touching it or not. The problem with this is that if the user touches the screen and keeps their finger in place while still touching the screen, onTouchEvent will not be called and screenTouched
will stay false
. Anyone know a way around this to be able to tell if the screen is being touched even if the users finger isn't moving?
来源:https://stackoverflow.com/questions/25755340/android-surfaceview-better-way-to-tell-if-screen-is-touched-java