c# XNA覆盖错误

本文关键字:错误 覆盖 XNA | 更新日期: 2023-09-27 17:50:39

我得到一个错误,

"错误1 ' gamestatmanagement . gameplayscreen . draw (Microsoft.Xna.Framework.GameTime,':没有找到合适的方法override"

我不知道怎么了。我是一个编程新手,从我的大学课程中得到了一些代码。其余的都是我自己做的。我不知所措,我该如何解决这个问题?

代码
        /// 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
    }
}

c# XNA覆盖错误

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

protected virtual void Draw (
    GameTime gameTime
)

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

protected virtual void Draw (
     GameTime gameTime,
     InputState input
)

在你的超类Game中不存在

(参见Game)。绘制方法。)

尝试删除关键字override

public void Draw(GameTime gameTime, InputState input)