title: getting X and Y values from an onTouchEvent in android
body: <p>I am developing an Android airplane shooter game and I need to get the X and Y position each time the player moves his airplane in order to detect collision.</p>
  
  <p>the class below handles the movement of the player's airplane</p>
  
  <pre><code>package com.pe44.dukes;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.MotionEvent;
  
  public class DukesGame extends Activity {
      final DukesEngine gameEngine = new DukesEngine();
      private DukesGameView gameView;
      public static float playerPosX, playerPosY;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          gameView = new DukesGameView(this);
          setContentView(gameView);
      }
      @Override
      protected void onResume() {
         super.onResume();
         gameView.onResume();
      }
  
      @Override
      protected void onPause() {
         super.onPause();
         gameView.onPause();
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          //
          playerPosX = event.getX();
          playerPosY = event.getY();
          String SPposX = Float.toString(playerPosX);
          String SPposY = Float.toString(playerPosY);
          Log.i(SPposX, SPposY);
          int height = DukesEngine.display.getHeight() / 4;
          int playableArea = DukesEngine.display.getHeight() - height;
          if (playerPosY &gt; playableArea){
              switch (event.getAction()){
              case MotionEvent.ACTION_DOWN:
                  if(playerPosX &lt; DukesEngine.display.getWidth() / 2){
                      DukesEngine.playerFlightAction = DukesEngine.player_turn_left;
                  }else{
                      DukesEngine.playerFlightAction = DukesEngine.player_turn_right;
                  }
                  break;
              case MotionEvent.ACTION_UP:
                  DukesEngine.playerFlightAction = DukesEngine.PLAYER_RELEASE;
                  break;
              }
  
          }
  
          return false;
      }
      public static float getPlayerX(){
          return playerPosX;
      }
      public static float getPlayerY(){
          return playerPosY;
      }
  
  }
  </code></pre>
  
  <p>I need to pass the <code>playerPosX = event.getX(); and playerPosY = event.getY();</code> into my renderer class which is going to handle the collision detection.</p>
  
  <p>I have created two get methods</p>
  
  <pre><code>public static float getPlayerX(){
      return playerPosX;
  }
  public static float getPlayerY(){
      return playerPosY;
  }
  </code></pre>
  
  <p>the piece of code which i wrote to handle the collision detection in the renderer class</p>
  
  <pre><code>private void detectCollisionsOnPlayer(){
      float playerPosX = DukesGame.getPlayerX();
      float playerPosY = DukesGame.getPlayerY();
      String posx = Float.toString(playerPosX);
      String posy = Float.toString(playerPosX);
      Log.d(posx,posy);
      for (int d = 0; d &lt; 3; d++){
          for (int x = 0; x &lt; DukesEngine.total_fighters + DukesEngine.total_jets + DukesEngine.total_warships - 1; x++ ){
              if(enemies[x].posX == playerPosX &amp;&amp; enemies[x].posY == playerPosY ){
                  Log.d("Game Over", "game over");
              }
          }
      }
  }
  </code></pre>
  
  <p>For some reason the X and Y values do not pass into the two methods I created in the DukesGame class. Can anyone suggest a solution for this problem?</p>