嗨,我尝试只为 Android 做一个视频游戏,但我不能使用 c 或其他环境。我不明白如何使用路径来移动我的图像,因为 pathinterpolator 请求从 (0,0) 开始并在 (1,1) 结束,但是如果我想在 (x,y) 中移动 al 我该怎么做? 我已经写了 onTouchEvent 的一部分,但我不理解文档。请帮助我和所有人。
这是我的方法 @Override public boolean onTouchEvent(MotionEvent event) {
int action = event.getActionMasked();
float newX = event.getX();
float newY = event.getY();
switch (action) {
case (MotionEvent.ACTION_DOWN):
Log.d(DEBUG_TAG, "Action was DOWN");
Path path = new Path();
path.moveTo(newX,newY);
PathInterpolator pathInterpolator = new PathInterpolator(path);
ObjectAnimator animation = ObjectAnimator.ofFloat(PG, "translationX", 100f);
animation.setInterpolator(pathInterpolator);
animation.start();
break;
case (MotionEvent.ACTION_MOVE):
Log.d(DEBUG_TAG, "Action was MOVE");
break;
case (MotionEvent.ACTION_UP):
Log.d(DEBUG_TAG, "Action was UP");
break;
case (MotionEvent.ACTION_CANCEL):
Log.d(DEBUG_TAG, "Action was CANCEL");
break;
case (MotionEvent.ACTION_OUTSIDE):
Log.d(DEBUG_TAG, "Movement occurred outside bounds " +
"of current screen element");
break;
}
return true;
}