0

我收到一个错误,

“错误 1 ​​'GameStateManagement.GameplayScreen.Draw(Microsoft.Xna.Framework.GameTime, GameStateManagement.InputState)':找不到合适的方法来覆盖”

我不知道出了什么问题。我是编程新手,并从我的大学课程中获得了一些代码。其余的我自己做。我很茫然,我该如何解决这个问题?

代码

        /// Draws the gameplay screen.
        /// </summary>
        public override void Draw(GameTime gameTime, InputState input)
        {
            // This game has a blue background. Why? Because! Not anymore, haha!

            var colorMatch = new Dictionary<int, Color>();
            colorMatch.Add(1, Color.LightBlue);
            colorMatch.Add(2, Color.CornflowerBlue);
            colorMatch.Add(3, Color.Blue);
            colorMatch.Add(4, Color.White);
            colorMatch.Add(5, Color.LightGreen);
            colorMatch.Add(6, Color.Green);
            colorMatch.Add(7, Color.Purple);
            colorMatch.Add(8, Color.Chocolate);
            colorMatch.Add(9, Color.Crimson);
            colorMatch.Add(10, Color.IndianRed);

            ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
                                               colorMatch[munchieSpeed], 0, 0);

            spriteBatch.Begin();

            // Draw munchies

            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            for (int i = 0; i < noOfMunchies; i++)
            {
                if (munchieAnimationCount[i] == 0)
                {
                    // Draw frame 1
                    if ((gamePadState.DPad.Right == ButtonState.Pressed) ||
                   (keyboardState.IsKeyDown(Keys.Right)))
                    {
                        spriteBatch.Draw(right, munchiePos[i], Color.White);
                    }
                    if ((gamePadState.DPad.Left == ButtonState.Pressed ||
                        (keyboardState.IsKeyDown(Keys.Left))))
                    {
                        spriteBatch.Draw(left, munchiePos[i], Color.White);
                    }
                    else if ((gamePadState.DPad.Up == ButtonState.Pressed ||
                        (keyboardState.IsKeyDown(Keys.Up))))
                    {
                        spriteBatch.Draw(up, munchiePos[i], Color.White);
                    }

                    else if ((gamePadState.DPad.Down == ButtonState.Pressed ||
                        (keyboardState.IsKeyDown(Keys.Down))))
                    {
                        spriteBatch.Draw(down, munchiePos[i], Color.White);
                    }
                }
                else
                {
                    // Draw frame 2
                    spriteBatch.Draw(left_2, munchiePos[i], Color.White);
                }
            }

            // Draw Pacman

            spriteBatch.Draw(pacman, pacmanPos,
                             new Rectangle(currentFrame.X * frameSize.X,
                                           currentFrame.Y * frameSize.Y,
                                           frameSize.X,
                                           frameSize.Y),
                             Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);

            spriteBatch.End();

            // If the game is transitioning on or off, fade it out to black.
            if (TransitionPosition > 0 || pauseAlpha > 0)
            {
                float alpha = MathHelper.Lerp(1f - TransitionAlpha, 1f, pauseAlpha / 2);

                ScreenManager.FadeBackBufferToBlack(alpha);
            }

            //Draw Score
            DrawText(points.ToString());
        }

        //Draw Scores
        private void DrawText(string score)
        {
            var CourierNew = content.Load<SpriteFont>("Fonts/menufont");
            spriteBatch.Begin();
            spriteBatch.DrawString(CourierNew, "Score: " + score, new Vector2(25, 0), Color.Black);
            spriteBatch.DrawString(CourierNew, "Lives: " + lives, new Vector2(700, 0), Color.Black);
            spriteBatch.End();
        }

        #endregion
    }
}
4

2 回答 2

3

您只能覆盖超类中定义的方法。这意味着当您实现一个继承自的类时Game(就像您在编写 XNA 游戏时所做的那样),您可以从Game具有以下签名的类中覆盖 draw 方法:

protected virtual void Draw (
    GameTime gameTime
)

在您的代码中,您试图覆盖一个方法,

protected virtual void Draw (
     GameTime gameTime,
     InputState input
)

这在您的超类中不存在,Game.

(另见Game.Draw 方法。)

于 2013-01-04T21:07:03.347 回答
1

尝试删除关键字override.

public void Draw(GameTime gameTime, InputState input)
于 2013-01-04T20:59:55.397 回答