画像付きのラベルを円形パスで移動する必要があるシミュレーションのようなスプライトを書いています。出発点は 4 つあります。西、北、東、南。ラベルは時計回りに移動する必要があります。
これは私が書いたもので、北と南の位置が反時計回りに回転するという事実を除いて、うまく機能します。その理由は、方向 2 と 4 を処理するために別の三角関数を使用したからです。
int xstart = 450
int ystart = 325;
int h = 0;
double theta = -0.1047;
for (int p = 0;; p++)
{
int xocir = xstart;
int yocir = ystart;
int pocir = 0; // perpendicular and base of outer circle
int bocir = 0;
if (direction == 1)//west - clockwise
{
pocir = (int) (Math.cos(theta) * (h + 300));
bocir = (int) (Math.sin(theta) * (h + 300));
}
else if (direction == 2)//north - counter-clockwise
{
pocir = (int) (Math.sin(theta) * (h + 300));//reversed sin,cos
bocir = (int) (Math.cos(theta) * (h + 300));
}
else if (direction == 3)//east - clockwise
{
pocir = (int) (Math.cos(theta) * (h - 300));
bocir = (int) (Math.sin(theta) * (h - 300));
}
else if (direction == 4)//south - counter-clockwise
{
pocir = (int) (Math.sin(theta) * (h - 300));
bocir = (int) (Math.cos(theta) * (h - 300));
}
xocir = xocir - pocir;
yocir = yocir - bocir;
theta = theta - 0.005;
setBounds(xocir, yocir, 65, 65);
}
これに取り組むより効率的な方法はありますか?たぶん、より単純なトリガー方法です。そして、すべての動きが時計回りであることを確認するにはどうすればよいですか?