如何更改Vector2?

时间:2014-02-18 18:25:15

标签: c# xna

所以我写了一个小方法来为我做这个,但我觉得这在某种意义上应该已经存在了。

position = ChangeVector(250.0f + somefloat, 100.0f + someotherfloat);


public Vector2 ChangeVector(float X, float Y)
{
    Vector2 Vector = new Vector2();
    Vector.X = X;
    Vector.Y = Y;
    return Vector;
}

我觉得我应该输入类似的内容:

position = (250.0f + somefloat, 100.0f + someotherfloat);

这更多是出于好奇而不是其他任何事情,我这样做的方式确实很好,看起来很麻烦。

1 个答案:

答案 0 :(得分:1)

您可以使用overloaded constructor Vector2 Constructor (Single, Single)

position = new Vector2(250.0f + somefloat, 100.0f + someotherfloat);