I have a ball in the screen .I want When I implemented action_down , the ball will move to this position .This my code :
public boolean onTouchEvent(MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN){
x1 = (int) event.getX();
y1 = (int) event.getY();
float dx = x1-x;
float dy = y1-y;
float d = (float)Math.sqrt(dx*dx+dy*dy);
vx = dx*4/d;
vy = dy*4/d;
}
}
and onDraw:
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
Matrix matrix = new Matrix();
matrix2.postTranslate(x - bitmap.getWidth()/2, y - bitmap.getHeight()/2);
x = x+vx ;
y = y+vy ;
canvas.drawBitmap(bitmap, matrix, null);
}
When ,the ball will move to position action_down .But Why the ball was in the position action_down ,it don't stop ?
Please help me?
Thank you?
No comments:
Post a Comment