没有合适的方法来覆盖Update(GameTime gameTime)

时间:2012-03-09 13:01:52

标签: c#-4.0 xna-4.0

我得到了上面提到的错误,这使我无法测试我的相机是否正常工作。代码是:

protected override void Update(GameTime gameTime)
{
    KeyboardState keyBoardState = Keyboard.GetState();

    //Rotate Cube along its Up Vector
    if (keyBoardState.IsKeyDown(Keys.X))
    {
        cubeWorld = Matrix.CreateFromAxisAngle(Vector3.Up, .02f) * cubeWorld;
    }
    if (keyBoardState.IsKeyDown(Keys.Z))
    {
        cubeWorld = Matrix.CreateFromAxisAngle(Vector3.Up, -.02f) * cubeWorld;
    }

    //Move Cube Forward, Back, Left, and Right
    if (keyBoardState.IsKeyDown(Keys.Up))
    {
        cubeWorld *= Matrix.CreateTranslation(cubeWorld.Forward);
    }
    if (keyBoardState.IsKeyDown(Keys.Down))
    {
        cubeWorld *= Matrix.CreateTranslation(cubeWorld.Backward);
    }
    if (keyBoardState.IsKeyDown(Keys.Left))
    {
        cubeWorld *= Matrix.CreateTranslation(-cubeWorld.Right);
    }
    if (keyBoardState.IsKeyDown(Keys.Right))
    {
        cubeWorld *= Matrix.CreateTranslation(cubeWorld.Right);
    }
}

导致错误的行是:

protected override void Update(GameTime gameTime)

1 个答案:

答案 0 :(得分:0)

您不是从GameComponent继承,您有两个选择:

  1. 从GameComponent继承你的类:

    public class YourCameraClass : GameComponent { .... }
    
  2. 删除更新方法声明中的'override'关键字:

    public void Update(Gametime gametime) {....}