I have class that extends View.
private class Draw2D extends View{
public Draw2D(Context context) {
super(context);
}
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.
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.