title: Moving sprite from point to point
body: <p>I want to move a sprite between two points.</p>
  
  <p>first point is <code>x=0</code> and <code>y=0</code> and the second point is a point where the user touched the screen.</p>
  
  <p>To move, I want to use an equation to go through the two points which is <code>y=ax+b</code>.</p>
  
  <p>I have attempted this in the method <code>move()</code> but the sprite does not move.</p>
  
  <p>Please help.</p>
  
  <p>Class Display:</p>
  
  <pre><code>package com.example.name;
  
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Canvas;
  import android.graphics.Color;
  import android.view.MotionEvent;
  import android.view.SurfaceHolder;
  import android.view.SurfaceView;
  
  public class Display extends SurfaceView {
  private Bitmap bmp;
  private SurfaceHolder holder;
  private GameLoopThread gameLoopThread;
  private Sprite sprite;
  private long lastClick;
  private float x = 0.0F;
  private float y = 0.0F;
  
  public Display(Context context) {
      super(context);
  
      bmp = BitmapFactory.decodeResource(getResources(), R.drawable.gonia);
      sprite = new Sprite(this, bmp, x, y, x, y);
  
      gameLoopThread = new GameLoopThread(this);
      holder = getHolder();
      holder.addCallback(new SurfaceHolder.Callback() {
  
          @Override
          public void surfaceDestroyed(SurfaceHolder holder) {
              boolean retry = true;
              gameLoopThread.setRunning(false);
              while (retry) {
                  try {
                      gameLoopThread.join();
                      retry = false;
                  } catch (InterruptedException e) {
                  }
              }
          }
  
          @Override
          public void surfaceCreated(SurfaceHolder holder) {
              gameLoopThread.setRunning(true);
              gameLoopThread.start();
          }
  
          @Override
          public void surfaceChanged(SurfaceHolder holder, int format,
                  int width, int height) {
          }
      });
  
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      canvas.drawColor(Color.BLACK);
      sprite.onDraw(canvas);
  }
  
  @Override
  public boolean onTouchEvent(MotionEvent event) {
      if (System.currentTimeMillis() - lastClick &gt; 500) {
          lastClick = System.currentTimeMillis();
          x = (float) sprite.ostatniaWartoscX();
          y = (float) sprite.ostatniaWartoscY();
          float gotox = (float) event.getX();
          float gotoy = (float) event.getY();
          synchronized (getHolder()) {
              sprite = new Sprite(this, bmp, x, y, gotox, gotoy);
  
          }
      }
      return true;
  }
  
  }
  </code></pre>
  
  <p>Class Sprite:</p>
  
  <pre><code>package com.example.name;
  
  import android.graphics.Bitmap;
  import android.graphics.Canvas;
  
  
  public class Sprite {
  
  
  private float a;
  private float b;
  
  private float x;
  private float y;
  private float gotox;
  private float gotoy;
  private int executeMove = 0;
  private Display display;
  private Bitmap bmp;
  
  
  public Sprite(Display display, Bitmap bmp, float x, float y, float gotox,
          float gotoy) {
      this.display = display;
      this.bmp = bmp;
      this.x = x;
      this.y = y;
      this.gotox = gotox;
      this.gotoy = gotoy;
  }
  
  void update() {
  
      if (x &lt; gotox) {x++;executeMove = 1;}
      if (x &gt; gotox) {x--;executeMove = 1;}
  
      if (executeMove == 1) {move();}
      executeMove = 0;
  
  
  }
  
  void move() {
      float x1 = x;
      float y1 = y;
      float x2 = gotox;
      float y2 = gotoy;
  
      a = (y2-y1)/(x2-x1);
      b = y1 - x1*a;
      y = x1 * a + b;
  
  
  }
  
  
  public float ostatniaWartoscX() {
      return x;
  }
  
  public float ostatniaWartoscY() {
      return y;
  }
  
  public void onDraw(Canvas canvas) {
      update();
      canvas.drawBitmap(bmp, x, y, null);
  }
  
  }
  </code></pre>
  
  <p>Thank You!</p>