2
我寫這樣的屬性(表示方向爲我XNA遊戲對象):分配和方法調用順序
public Vector2 Direction
{
get { return direction; }
protected set
{
(direction = value).Normalize(); // ***
angle = MathHelper.WrapAngle((float)Math.Atan(direction.X/direction.Y));
}
}
組設置其表示對象的方向在角並且同時在歸一化矢量兩個等價的字段。
開始遊戲失敗,因爲線路標有***失敗。它沒有標準化向量。
我改變了這一行:
direction = value;
direction.Normalize();
,它工作正常,爲什麼?
我假設在標有***的行中,第一個操作是指定值,然後正常化方向。但事實並非如此。
_ __ __ __ ___
正常化()是從方法Vector2類。
//
// Summary:
// Turns the current vector into a unit vector. The result is a vector one unit
// in length pointing in the same direction as the original vector.
public void Normalize();
請爲您正在討論的語言添加標籤。 – Mat
請包括拋出的異常/錯誤消息導致遊戲失敗。 – StellarEleven
「遊戲失敗」我的意思是遊戲的邏輯沒有正確更新。 –