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
Related
I asked a similar question before but the answer was not very helpful and I can't find any solution for this problem.
I want to know a method to detect ACTION_DOWN when we only touch a certain view and to detect ACTION_MOVE when we only move our finger on screen, because all I am getting is ACTION_DOWN and ACTION_MOVE being called at the same time when I place my finger on the view.
can anyone please post a simple code for how to do that.
That are raw motion events. You can probably use GestureDetector and detect click and swipe.
Problem is that ACTION_MOVE will be called when any move is detected, for example applying just a little more pressure when touching screen might move touch point few pixels around.
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)
I am testing this sample on version 13 of android (3.2) and I have an issue when there is multiple touches on screen.
When I first touch, then there is an action_down event, if I make another simultaneous touch, then I won't get another action_down, my first touch keeps active and I can keep getting action_move from the first touch.
The problem is, when I release the first touch and move the second, it creates a line to that touch, because it generates another action_move event.
I tried using Euclidean distance, but it seems to slow down too much, and makes the lines incomplete.
I tried creating a producer/consumer model, but still got the same problem.
I also tried checking the time from the last touch, but this is very inefficient.
Does anyone have any suggestion?
I admit I'm a little confused about what your actual problem is, but it seems to me like your problem might be solved simply by handling more of the touch events. When the second finger comes down, you can get an ACTION_POINTER_DOWN event, indicating a second touch, and you can then modify how your ACTION_MOVE events will be interpreted while the second finger is down, until an ACTION_POINTER_UP event comes through. Hope that answers or at least helps your question.
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.
I want to move an image around the screen according to the trackball movement. I am able to capture the movements using the onTrackballEvent method. But this is being called for very small float values (I believe for each rotation?) of the trackball.
Now as X and Y positions of views should be integers when specifying with LayoutParams, it makes no sense to move the view with every rotation. Instead I want to move the view only after the user stops rotating the trackball.
Is there any method by which we can get whether the user stopped using the trackball or not?
If there isn't (I don't know Android), the classic approach is to start a timer in each event, and keep track of the deltas reported in it (by adding them to a running sum, one for X and one for Y). On any subsequent event, before the timer has triggered, just re-start the same timer, pushing its triggering further into the future.
When the user stops generating events, the timer will eventually trigger, and then you can apply the sum of all the movements, and clear the sums.
A suitable timeout must be chosen so that the user interaction is not perceived as being too sluggish. Perhaps something on the order of 200-300 milliseconds, or more. This is easy to tweak until it feels "right".
I've also gotten a lot of value out of setting a threshold. So if the total movement in a specific direction adds up to a given amount, then trigger a navigational event.