0

三角法を使用して距離と角度を計算し、ダイナミック テキスト ボックスに表示するゲームを作成しています。ムービー クリップの中心からカーソルまでの距離を計算しています。そして、ムービー クリップのその中心を使用して、カーソルが swf の周りを移動するときに、完全な 360 度を計算して表示しようとしています。ゲームの距離部分は機能していますが、度数を表示する部分が正しく機能していません。ダイナミック テキスト ボックスは、90 度から 270 度までしか表示されません。270º から 360º / 0º から 90º を超える代わりに、270º から 90º にカウントダウンします。以下は私のアクションスクリプトです。助けや提案をいただければ幸いです。ありがとう!

//Mouse and Dynamic Text Boxes-------------------------

Mouse.hide();

onMouseMove = function () {
feedback.text = "You are moving your mouse";
cursor._x = _xmouse;
cursor._y = _ymouse;
updateAfterEvent();
xmouse_value.text = Math.atan2((a), (b));
ymouse_value.text = Math.round(radians*180/Math.PI)
updateAfterEvent();  
};

Mouse.addListener(myListener);


//distance (RANGE)
_root.onEnterFrame = function () {
xmid = Stage.width/2;
ymid = Stage.height/2;

a = _root._ymouse-ymid;
b = _root._xmouse-xmid;
c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2));
feedbacka.text = Math.round(a);
feedbackb.text = Math.round(b);
feedbackc.text = Math.round(c/30.4);

updateAfterEvent();  

var radians:Number;
var degrees:Number;

//Calculcate Radians
//Radians specify an angle by measuring the length around the path of the circle.
radians = Math.atan2((c), (b))

//calculate degrees
//the angle the circle is in relation to the center point
//update text box inside circle
radians_txt = Math.round(radians*360/Math.PI);
degrees_txt = Math.round(radians*180/Math.PI);

updateAfterEvent();  

//getting past 270 degrees

radians2_txt = Math.round(radians/Math.PI);
radians2_txt = Math.floor(radians + -270);

}
4

1 に答える 1

0

パラメータatan2は 2 点間の delta-y と delta-x である必要がありますが、2 点と delta-x の間の距離を渡しています。代わりにこれを試してください:

radians = Math.atan2(a, b);

次の問題は、ラジアンを度に変換することです。ラジアンを度に変換するには、次のようにします。

degrees_txt = radians * 180 / Math.PI;

から までの間にatan2戻ることに注意してください。度に変換すると、この範囲は -180 ~ 180 になります。0 ~ 360 に変換するには、結果が負の場合は 360 を追加します。-Math.PI / 2Math.PI / 2

if(degrees_txt < 0) degrees_txt += 360;
于 2012-04-05T02:27:50.533 に答える