-2
我在下面的代碼中一直收到這個錯誤。有人可以告訴我我做了什麼錯。 foreach語句無法在類型「方法組」的變量操作,因爲「法團」不包含公共定義爲XNA foreach語句錯誤
private void updateVelocity(KeyboardState keyboardState)
{
var keysdictionay = new Dictionary<Keys, Vector2>
{
{Keys.Left, new Vector2(-1, 0)},
{Keys.Right, new Vector2(1, 0)},
{Keys.Up, new Vector2(0, -1)},
{Keys.Down, new Vector2(0, 1)}
};
var velocity = Vector2.Zero;
foreach (var keypress in keyboardState.GetPressedKeys)
{
velocity += keysdictionay[keypress];
}
Velocity = velocity * shipspeed;
}
public Vector2 Velocity { get; set; }
float shipspeed = 300.0f;
}
}