2013-05-21 61 views
-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; 

    } 
} 

回答

4

GetPressedKeys is a method.使用()

foreach (var keypress in keyboardState.GetPressedKeys())