Pong game Android onTouchListener? - android

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)

Related

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.

Bouncing ball app in touch listener in android

I refer this link Bouncing Ball.When user touch on ball, it stops moving & When user release ball then it continues moving. how can we do it using touch gesture ?
Thank you in Advance.
As i said earlier that is much declarative answer to help you here.You need to share your code here to help something.
I would like to give you some hint to do this: override onTouchEvent(MotionEvent event) method. Use event.getAction() to catch various MotionEvent. When you can identify MotionEvent.ACTION_DOWN then set event.getX() and getY() as your objects current x,y. That will stop moving your object.
Similarly, at MotionEvent.ACTION_UP update your objects position(x,y according to the direction), and set yourObject.setTouched(false). So when user release his finger from the screen object will start to move again.

How to disable the move threshold when getting touch events?

I am creating an Android game that uses touch input. I noticed that, when I put down a finger and move it, there is a threshold of a couple of pixels until the first MotionEvent.ACTION_MOVE is generated. What is the correct way of disabling this threshold filter?
It's called touch slop. And here's the same question already answered: Android ACTION_MOVE Threshold

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.

How can I track a persons finger movement in 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

Categories

Resources