Guest User

Untitled

a guest
Jan 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. //global variables
  2. private int movePointerId = -1;
  3. private int shootingPointerId = -1;
  4.  
  5. public void update(MotionEvent event) {
  6.  
  7. if (event == null && lastEvent == null) {
  8. return;
  9. } else if (event == null && lastEvent != null) {
  10. event = lastEvent;
  11. } else {
  12. lastEvent = event;
  13. }
  14.  
  15. // grab the pointer id
  16. int action = event.getAction();
  17. int actionCode = action & MotionEvent.ACTION_MASK;
  18. int actionIndex = event.getActionIndex();
  19. int pid = action >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
  20. int x = (int) event.getX(pid);
  21. int y = (int) event.getY(pid);
  22. String actionString = null;
  23.  
  24.  
  25. switch (actionCode)
  26. {
  27. case MotionEvent.ACTION_DOWN:
  28. case MotionEvent.ACTION_POINTER_DOWN:
  29.  
  30. actionString = "DOWN";
  31. try{
  32. if(x > 0 && x < steeringxMesh + (joystick.get_joystickBg().getWidth() * 2)
  33. && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
  34. movingPoint.x = x;
  35. movingPoint.y = y;
  36. movePointerId = pid;
  37. dragging = true;
  38. //checks if Im pressing the joystick used for moving
  39. }
  40. else if(x > shootingxMesh - (joystick.get_joystickBg().getWidth()) && x < panel.getWidth()
  41. && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
  42. shootingPoint.x = x;
  43. shootingPoint.y = y;
  44. shootingPointerId = pid;
  45. shooting=true;
  46. //checks if Im pressing the joystick used for shooting
  47. }
  48. }catch(Exception e){
  49.  
  50. }
  51. break;
  52. case MotionEvent.ACTION_UP:
  53. case MotionEvent.ACTION_POINTER_UP:
  54. case MotionEvent.ACTION_CANCEL:
  55. case MotionEvent.ACTION_OUTSIDE:
  56.  
  57. if( pid == movePointerId ){
  58. movePointerId = -1;
  59. dragging = false;
  60. }
  61. else if( pid == shootingPointerId ){
  62. shootingPointerId = -1;
  63. shooting=false;
  64. }
  65. actionString = "UP";
  66. break;
  67. case MotionEvent.ACTION_MOVE: // this is where my problem is
  68.  
  69. if( pid == movePointerId ) {
  70. movingPoint.x = x;
  71. movingPoint.y = y;
  72. } else if( pid == shootingPointerId ) {
  73. shootingPoint.x = x;
  74. shootingPoint.y = y;
  75. }
  76. actionString = "MOVE";
  77. break;
  78.  
  79. }
  80.  
  81. //global variables
  82. private int movePointerId = -1;
  83. private int shootingPointerId = -1;
  84.  
  85. public void update(MotionEvent event) {
  86.  
  87. if (event == null && lastEvent == null) {
  88. return;
  89. } else if (event == null && lastEvent != null) {
  90. event = lastEvent;
  91. } else {
  92. lastEvent = event;
  93. }
  94.  
  95. // grab the pointer id
  96. int action = event.getAction();
  97. int actionCode = action & MotionEvent.ACTION_MASK;
  98. int pid = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
  99. int fingerid = event.getPointerId(pid);
  100.  
  101. //int actionIndex = event.getActionIndex();
  102. //int pid = action >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
  103. int x = (int) event.getX(pid);
  104. int y = (int) event.getY(pid);
  105. String actionString = null;
  106.  
  107.  
  108. switch (actionCode)
  109. {
  110. case MotionEvent.ACTION_DOWN:
  111. case MotionEvent.ACTION_POINTER_DOWN:
  112.  
  113. actionString = "DOWN";
  114. try{
  115. if(x > 0 && x < steeringxMesh + (joystick.get_joystickBg().getWidth() * 2)
  116. && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
  117. movingPoint.x = x;
  118. movingPoint.y = y;
  119. //movePointerId = pid;
  120. movePointerId = fingerid;
  121. dragging = true;
  122. //checks if Im pressing the joystick used for moving
  123. }
  124. else if(x > shootingxMesh - (joystick.get_joystickBg().getWidth()) && x < panel.getWidth()
  125. && y > yMesh - (joystick.get_joystickBg().getHeight()) && y < panel.getHeight()){
  126. shootingPoint.x = x;
  127. shootingPoint.y = y;
  128. //shootingPointerId = pid;
  129. shootingPointerId = fingerid;
  130. shooting=true;
  131. //checks if Im pressing the joystick used for shooting
  132. }
  133. }catch(Exception e){
  134.  
  135. }
  136. break;
  137. case MotionEvent.ACTION_UP:
  138. case MotionEvent.ACTION_POINTER_UP:
  139. case MotionEvent.ACTION_CANCEL:
  140. case MotionEvent.ACTION_OUTSIDE:
  141.  
  142. if( fingerid == movePointerId ){ //changed this line
  143. movePointerId = -1;
  144. dragging = false;
  145. }
  146. else if( fingerid == shootingPointerId ){ //changed this line
  147. shootingPointerId = -1;
  148. shooting=false;
  149. }
  150. actionString = "UP";
  151. break;
  152. case MotionEvent.ACTION_MOVE: // this is where my problem is
  153.  
  154. if( fingerid == movePointerId ) { //changed this line
  155. movingPoint.x = x;
  156. movingPoint.y = y;
  157. } else if( fingerid == shootingPointerId ) { //changed this line
  158. shootingPoint.x = x;
  159. shootingPoint.y = y;
  160. }
  161. actionString = "MOVE";
  162. break;
  163.  
  164. }
Add Comment
Please, Sign In to add comment