XNA foreach语句错误

时间:2013-05-21 14:22:48

标签: 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;

    }
}

1 个答案:

答案 0 :(得分:4)

GetPressedKeys is a method.在其上使用()

foreach (var keypress in keyboardState.GetPressedKeys())