Reputation: 655
I am writing a game which has three buttons, for left, right movement and jump.
Suppose, I press right button to move the character which is handled by MotionEvent.Action_Down
. While keeping the primary (right) button pressed I press the jump button which is handled by MotionEvent.Action_Pointer_Down
. Now I release the jump button which should move the control to Action_Pointer_Up
but I still want my character to move towards right as right button has not been released but I don't know how to handle this. Initially I thought that control will again shift to MotionEvent.Action_Down
but that isn't working.
Can anybody please help me here?
Upvotes: 0
Views: 308
Reputation: 1193
When handling touch events in Android, the onTouch handler only notifies you about changes in state. It does not send the entire state of the detected touches, instead you have to track the information you care about.
When a touch is first detected, the Action_Down event is sent, as you see. This is the start of a set of touch events, but will only ever signify one touch event. After, any new detected fingers will appears as Action_Pointer_Down, as you also saw. Each touch point will have its own id for the duration of its touch, so you can tell in the future which touch has moved where, if you care about the Action_Move events. As touch events go, you will see the Action_Pointer_Up. This will tell you which touch event left (which could be the first one). When the final touch is gone, Action_Up is triggered. At that point nothing is touching the screen.
For your case, what you see is what you expect given above. When the jump is removed, Action_Pointer_Up is triggered. All you need to do is verify that the jump touch was removed, and leave the character to move to the right. You won't see any more events for the move right signal, unless the user moves their finger or raises it.
Upvotes: 2