我一直在开发游戏,我很困惑我如何在TranslateAnimation
上使用TouchEvent
? ,请看我的代码,有些不对劲!? Fstball
尚未翻译,有任何想法吗?
@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;
}
答案 0 :(得分:2)
你应该像这样开始你的动画:
FstBall. startAnimation(anim); // FstBall is a View