Moving drawable follow the finger

前端 未结 2 537
一生所求
一生所求 2021-01-07 11:23

I have class that extends View.

private class Draw2D extends View{
             public Draw2D(Context context) {
        super(context);
              }

            


        
相关标签:
2条回答
  • 2021-01-07 12:03

    These Youtube tutorials do just this;

    Link: https://buckysroom.org/videos.php?cat=6

    Just watch the tutorials 71, 72 and 73 and it should work.

    0 讨论(0)
  • 2021-01-07 12:09

    You need to track the coordinates of your drawable so you can compare with the touch x, y coordinates.

    So basically:

    // can modify to adjust speed at which drawable moves
    int movementSpeed = 2;  
    
    if (drawableX < x)
      drawableX += movementSpeed;
    else if (drawableX > x)
      drawableX -= movementSpeed;
    
    if (drawableY < y)
      drawableY += movementSpeed;
    else if (drawableY > y)
      drawableY -= movementSpeed;
    

    Then need to redraw your drawable with the updated drawableX, drawableY coordinates.

    0 讨论(0)
提交回复
热议问题