我收到了错误,
“错误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
}
}
答案 0 :(得分:3)
您只能覆盖superclass中定义的方法。这意味着当您实现一个继承自Game
的类时(就像编写XNA游戏时那样),您可以从具有以下签名的类Game
覆盖draw方法:
protected virtual void Draw (
GameTime gameTime
)
在您的代码中,您正试图覆盖方法
protected virtual void Draw (
GameTime gameTime,
InputState input
)
在您的超类Game
中不存在。
(另请参阅 Game.Draw Method 。)
答案 1 :(得分:1)
尝试删除关键字override
。
public void Draw(GameTime gameTime, InputState input)