Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //global variables
- private int movePointerId = -1;
- private int shootingPointerId = -1;
- public void update(MotionEvent event) {
- if (event == null && lastEvent == null) {
- return;
- } else if (event == null && lastEvent != null) {
- event = lastEvent;
- } else {
- lastEvent = event;
- }
- // grab the pointer id
- int action = event.getAction();
- int actionCode = action & MotionEvent.ACTION_MASK;
- int actionIndex = event.getActionIndex();
- int pid = action >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
- int x = (int) event.getX(pid);
- int y = (int) event.getY(pid);
- String actionString = null;
- switch (actionCode)
- {
- case MotionEvent.ACTION_DOWN:
- case MotionEvent.ACTION_POINTER_DOWN:
- actionString = "DOWN";
- try{
- if(x > 0 && x < steeringxMesh + (joystick.get_joystickBg().getWidth() * 2)
- && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
- movingPoint.x = x;
- movingPoint.y = y;
- movePointerId = pid;
- dragging = true;
- //checks if Im pressing the joystick used for moving
- }
- else if(x > shootingxMesh - (joystick.get_joystickBg().getWidth()) && x < panel.getWidth()
- && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
- shootingPoint.x = x;
- shootingPoint.y = y;
- shootingPointerId = pid;
- shooting=true;
- //checks if Im pressing the joystick used for shooting
- }
- }catch(Exception e){
- }
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_POINTER_UP:
- case MotionEvent.ACTION_CANCEL:
- case MotionEvent.ACTION_OUTSIDE:
- if( pid == movePointerId ){
- movePointerId = -1;
- dragging = false;
- }
- else if( pid == shootingPointerId ){
- shootingPointerId = -1;
- shooting=false;
- }
- actionString = "UP";
- break;
- case MotionEvent.ACTION_MOVE: // this is where my problem is
- if( pid == movePointerId ) {
- movingPoint.x = x;
- movingPoint.y = y;
- } else if( pid == shootingPointerId ) {
- shootingPoint.x = x;
- shootingPoint.y = y;
- }
- actionString = "MOVE";
- break;
- }
- //global variables
- private int movePointerId = -1;
- private int shootingPointerId = -1;
- public void update(MotionEvent event) {
- if (event == null && lastEvent == null) {
- return;
- } else if (event == null && lastEvent != null) {
- event = lastEvent;
- } else {
- lastEvent = event;
- }
- // grab the pointer id
- int action = event.getAction();
- int actionCode = action & MotionEvent.ACTION_MASK;
- int pid = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
- int fingerid = event.getPointerId(pid);
- //int actionIndex = event.getActionIndex();
- //int pid = action >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
- int x = (int) event.getX(pid);
- int y = (int) event.getY(pid);
- String actionString = null;
- switch (actionCode)
- {
- case MotionEvent.ACTION_DOWN:
- case MotionEvent.ACTION_POINTER_DOWN:
- actionString = "DOWN";
- try{
- if(x > 0 && x < steeringxMesh + (joystick.get_joystickBg().getWidth() * 2)
- && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
- movingPoint.x = x;
- movingPoint.y = y;
- //movePointerId = pid;
- movePointerId = fingerid;
- dragging = true;
- //checks if Im pressing the joystick used for moving
- }
- else if(x > shootingxMesh - (joystick.get_joystickBg().getWidth()) && x < panel.getWidth()
- && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
- shootingPoint.x = x;
- shootingPoint.y = y;
- //shootingPointerId = pid;
- shootingPointerId = fingerid;
- shooting=true;
- //checks if Im pressing the joystick used for shooting
- }
- }catch(Exception e){
- }
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_POINTER_UP:
- case MotionEvent.ACTION_CANCEL:
- case MotionEvent.ACTION_OUTSIDE:
- if( fingerid == movePointerId ){ //changed this line
- movePointerId = -1;
- dragging = false;
- }
- else if( fingerid == shootingPointerId ){ //changed this line
- shootingPointerId = -1;
- shooting=false;
- }
- actionString = "UP";
- break;
- case MotionEvent.ACTION_MOVE: // this is where my problem is
- if( fingerid == movePointerId ) { //changed this line
- movingPoint.x = x;
- movingPoint.y = y;
- } else if( fingerid == shootingPointerId ) { //changed this line
- shootingPoint.x = x;
- shootingPoint.y = y;
- }
- actionString = "MOVE";
- break;
- }
Add Comment
Please, Sign In to add comment