あなたの質問は実際にはかなり曖昧であり、私たちがあなたのシナリオを理解するのを助けるために、あなたが実際にいくつかのコードスニペット、変数、式を提供した場合に役立ちます。私は答えを導くのを助けるために以下の仮定をするつもりです:
- (x1、y1)-(x2、y2)で定義された線分があります
- 線分に続くオブジェクトのアニメーションを作成したい
- オブジェクトを正しい方向に向ける必要があります
- オブジェクトが1秒あたり1ピクセルの速度で移動すると仮定します
これでパラメータが確立されたので、Javaコードを提供できます。
// Define the line segment.
double x1 = /* ... insert value here */;
double y1 = /* ... insert value here */;;
double x2 = /* ... insert value here */;;
double y2 = /* ... insert value here */;;
// Determine both the direction and the length of the line segment.
double dx = x2 - x1;
double dy = y2 - y1;
double length = Math.sqrt(dx * dx + dy * dy); // length of the line segment
double orientation = Math.atan2(dy, dx);
// Now for any time 't' between 0 and length, let's calculate the object position.
double x = x1 + t * dx / length;
double y = y1 + t * dy / length;
showObjectAt(x, y, orientation);
アプリケーションのゲームループの構築に関するチュートリアルに従うことに関しては、http://www.mybringback.com/のシリーズ、特にhttp://wwwのSurfaceViewオブジェクトの操作に関するTravisのAndroidチュートリアルに従うことを強くお勧めします。mybringback.com/tutorial-series/3266/android-the-basics-28-introduction-to-the-surfaceview/