-2

我在下面的代码中不断收到此错误。有人可以告诉我我做错了什么。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;

    }
}
4

1 回答 1

4

GetPressedKeys is a method. 使用()

foreach (var keypress in keyboardState.GetPressedKeys())
于 2013-05-21T14:26:09.440 回答