How can I track a persons finger movement in android? - android

I am trying to create an app that has you put your finger on a starting point ( an area with 150dpx150dp) and have it go through a specific pattern (like a maze).
How should I go about doing this? (I'm used to using the given buttons to do things)

Handle the OnTouch Event to get the coordinates of the touch.
The event contains a instance of the MotionEvent class.
The process to move the object(eg current painting location) would be:
b=get previous touch coordinates
a=get cordinates of current touch
move object from location b to a

Use gesture - http://developer.android.com/resources/articles/gestures.html

Related

react native - Long press move

I want to handle a press In react native app, so that :
When I touch the screen and move my finger across the screen,
I want to show the coordinates X and Y in real time, so by moving my finger the coordinates changes.
You can use react-native-gesture-handler and react-native-gesture-detector to detect custom gestures which allow you to create gestures on the fly. Yep, just plug it in, paint the gesture and you will receive the coordinate data for your super-complex, custom gesture. You can use it to just use the data points as a predefined gesture in your app, or you can even let your app users create their own custom gestures

OpenGL sprite looses focus on fast move

I'm making simple app where user can move squares with finger on screen. First I'm checking if touch coords are on square to allow the move. Then square is moving along GLSurfaceView#onTouchEvent event coordinates.
It works OK. But when finger is moving too quick (like swipe) square looses the focus and stays still. It seems that OpenGL renders square after the move event occurs, so coordinates check fail.
Please point some keywords to figure out the question (googling gives same links again and again) or some docs. Thanks.
You need hold focus on sprite. If sprite got event "down" it holds focus until doesn't get "up" or "cancel" event. So, while sprite holds focus all touch events send to it.

Which method gives the exact coordinates as those given by GestureDetector

I want to develop an App. that can detect if the user touches a specific view, so that certain action to happen. I implemented SimpleOnGestureListener to detect and listen users' touches across the screen. My problem now is, the below posted methods, give different coordinates of the same view and i do not know which one should i use to compare with the coordinates given by the SimpleOnGestureListener.
Methods that give coordinates of the views:
tv1.getLocalVisibleRect(tv1Rect);
tv1.getLocationOnScreen(tv1LocOnScreen);
tv1.setText("xCords: "+tv1.getX()+", yCords: "+tv1.getY());
To find out if a view contains the point touched you can use
CGRectContainsPoint(your view frame, the CGPoint of the tap)
You can get the CGPoint of the tap from a gesture recognizer by
CGPoint location = [recognizer locationInView: view which the recognizer is attached to];

Pong game Android onTouchListener?

So basically I made the screen with 2 paddles and a very simple score board. I've been researching a little and found the onTouch method. But that only works for 1 paddle. How about 2 player? Is there a onTouch and drag method, because I want the player to touch the paddle and move it right or left. And lastly how can I do that for both of the paddles?
Thanks in advance.
Read more here. onTouchEvent receives MotionEvent object, and you can handle multiple touches using event.getActionIndex() and event.getPointerId(). You should probably determine if you're moving tob or bottom paddle by initial touch coordinates, and then handle events properly (by moving paddle that matches PointerId for example)

How to get the direction of the finger in android game

I am trying to develop a game with Android where I need to move a tile in all directions. My question is how can I get the motion of the finger on the screen(right,left,top) using getX() and getY()?
Thanks.
Take a look at getHistoricalSize, getHistoricalX(int) and getHistoricalY(int).
When the finger is touching the screen, Android records the move positions and saves them. You can then call getHistorySize to get the number of motions recorded, and then call getHistoricalX and getHistoricalY with a parameter less that the history size to get the x/y at that history position.
So, for example, you can call getHistoricalY with a parameter that indicates that previous motion event, and then compare it to the current one. If the current one is bigger, then the finger is swiping down.
Note: Motion events recording applies only to ACTION_MOVE.

Categories

Resources