In my app I draw an image covering the entire screen. I want to now how can I know where the user touched the screen?
Thanks
In my app I draw an image covering the entire screen. I want to now how can I know where the user touched the screen?
Thanks
Answered here: http://stackoverflow.com/questions/3637827/how-do-i-get-the-x-y-coordinate-for-a-screen-touch/
Here is a snippet of one of my games that does this. There are different ways to do it, but here I did it by subclassing View:
public class WorldView extends View {
...
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
Log.d(TAG,"touch event "+action+" x="+event.getX()+" y="+event.getY());
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE)
{
int x = (int)event.getX();
int y = (int)event.getY();
Log.d(TAG,"setting target to "+x+","+y);
}
else
return super.onTouchEvent(event);
return true;
}