I have been developing a game and I’m confuse that How can I use TranslateAnimation on TouchEvent ? , Please look at my code , something is wrong !? Fstball has not been translated , Any ideas?
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int X = (int) event.getX();
int Y = (int) event.getY();
int action = event.getAction();
if (action == MotionEvent.ACTION_UP){
TranslateAnimation anim = new TranslateAnimation(FstBall.getLeft(),X,FstBall.getTop()
,Y);
anim.setFillAfter(true);
anim.setDuration(1000);
FstBall.setAnimation(anim);
} else {
Toast.makeText(this,"Touch any points to move.", Toast.LENGTH_SHORT).show();
}
return true;
}
you should start your animation like this :