title: Java LibGDX Moving to Touch Position on Android
body: <p>I'm using this code but somethings aren't perfect. It's working but not smooth. First it goes touchX and then goes touchY. But I want this at the same time. I tried different codes but didn't work. How can I fix it? What's the problem?</p>
  
  <pre><code>package com.anil.game1;
  import com.badlogic.gdx.ApplicationAdapter;
  import com.badlogic.gdx.Gdx;
  import com.badlogic.gdx.graphics.GL20;
  import com.badlogic.gdx.graphics.OrthographicCamera;
  import com.badlogic.gdx.graphics.Texture;
  import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  import com.badlogic.gdx.math.Rectangle;
  import com.badlogic.gdx.math.Vector3;
  public class Game1 extends ApplicationAdapter {
      private SpriteBatch batch;
      private OrthographicCamera camera;
      private Texture player1Texture;
      private Rectangle player1Rectangle;
      private Vector3 touchPos;
      @Override
      public void create () {
          batch = new SpriteBatch();
          camera = new OrthographicCamera(480, 800);
          player1Texture = new Texture("Player1.png");
          player1Rectangle = new Rectangle();
          player1Rectangle.set(240, 0, 64, 64);
          touchPos = new Vector3();
      }
      @Override
      public void render () {
          Gdx.gl.glClearColor(0, 0, 0, 1);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
          batch.setProjectionMatrix(camera.combined);
          batch.begin();
          if (Gdx.input.isTouched()) {
              touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
              camera.unproject(touchPos);
              //player1Rectangle.setPosition(new Vector2(touchPos.x, touchPos.y));
          }
          if (touchPos.x &gt; player1Rectangle.x)
              player1Rectangle.x += 5;
          else
              player1Rectangle.x -= 5;
          if (touchPos.y &gt; player1Rectangle.y)
              player1Rectangle.y += 5;
          else
              player1Rectangle.y -= 5;
          batch.draw(player1Texture, player1Rectangle.x - 32, player1Rectangle.y - 32);
          batch.end();
      }
      @Override
      public void dispose () {
          batch.dispose();
          player1Texture.dispose();
      }
  }
  </code></pre>