Hi,
I'm relatively new to C#. At the moment I am creating a menu for a gaming project that I am developing.
The menu that I am having a problem with is the Gameplay Screen. I am trying to put my own code in to display a model from the tutorial on menus from this site.
I am getting this error: GameStateManagement.GameplayScreen.LoadGraphicsContent(bool)': no suitable method found to override.
Here is the code that is giving me that error:
namespace GameStateManagement
{
/// <summary>
/// This screen implements the actual game logic. It is just a
/// placeholder to get the idea across: you'll probably want to
/// put some more interesting gameplay in here!
/// </summary>
public partial class GameplayScreen : GameScreen
{
#region Fields
ContentManager content;
SpriteFont gameFont;
Vector2 playerPosition = new Vector2(100, 100);
Vector2 enemyPosition = new Vector2(100, 100);
Random random = new Random();
GraphicsDeviceManager graphics;
Tank tank;
#endregion
#region Initialization
/// <summary>
/// Constructor.
/// </summary>
public GameplayScreen()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
content.RootDirectory = "Content";
TransitionOnTime = TimeSpan.FromSeconds(1.5);
TransitionOffTime = TimeSpan.FromSeconds(0.5);
graphics.PreferredBackBufferWidth = 853;
graphics.PreferredBackBufferHeight = 480;
tank = new Tank();
}
/// <summary>
/// Load graphics content for the game.
/// </summary>
protected override void LoadGraphicsContent(bool loadAllContent) -- This is where I get the error
{
if (loadAllContent)
{
tank.Load(Content);
}
}
/// <summary>
/// Unload your graphics content. If unloadAllContent is true, you should
/// unload content from both ResourceManagementMode pools. Otherwise, just
/// unload ResourceManagementMode.Manual content. Manual content will get
/// Disposed by the GraphicsDevice during a Reset.
/// </summary>
/// <param name="unloadAllContent">Which type of content to unload.</param>
protected void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent == true)
{
content.Unload();
}
}
#endregion
#region Update and Draw
/// <summary>
/// Updates the state of the game. This method checks the GameScreen.IsActive
/// property, so the game will stop updating when the pause menu is active,
/// or if you tab away to a different application.
/// </summary>
public override void Update(GameTime gameTime, bool otherScreenHasFocus,
bool coveredByOtherScreen)
{
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
if (IsActive)
{
// Apply some random jitter to make the enemy move around.
const float randomization = 10;
enemyPosition.X += (float)(random.NextDouble() - 0.5) * randomization;
enemyPosition.Y += (float)(random.NextDouble() - 0.5) * randomization;
// Apply a stabilizing force to stop the enemy moving off the screen.
Vector2 targetPosition = new Vector2(200, 200);
enemyPosition = Vector2.Lerp(enemyPosition, targetPosition, 0.05f);
HandleInput();
float time = (float)gameTime.TotalGameTime.TotalSeconds;
// Update the animation properties on the tank object. In a real game
// you would probably take this data from user inputs or the physics
// system, rather than just making everything rotate like this!
tank.WheelRotation = time * 5;
tank.SteerRotation = (float)Math.Sin(time * 0.75f) * 0.5f;
tank.TurretRotation = (float)Math.Sin(time * 0.333f) * 1.25f;
tank.CannonRotation = (float)Math.Sin(time * 0.25f) * 0.333f - 0.333f;
tank.HatchRotation = MathHelper.Clamp((float)Math.Sin(time * 2) * 2, -1, 0);
base.Update(gameTime);
}
}
private void HandleInput()
{
KeyboardState currentKeyboardState = Keyboard.GetState();
GamePadState currentGamePadState = GamePad.GetState(PlayerIndex.One);
// Check for exit.
if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
currentGamePadState.Buttons.Back == ButtonState.Pressed)
{
Exit();
}
}
/// <summary>
/// Draws the gameplay screen.
/// </summary>
public override void Draw(GameTime gameTime)
{
GraphicsDevice device = graphics.GraphicsDevice;
device.Clear(Color.DarkGray);
// Calculate the camera matrices.
Viewport viewport = device.Viewport;
float aspectRatio = (float)viewport.Width / (float)viewport.Height;
float time = (float)gameTime.TotalGameTime.TotalSeconds;
Matrix rotation = Matrix.CreateRotationY(time * 0.1f);
Matrix view = Matrix.CreateLookAt(new Vector3(1000, 500, 0),
new Vector3(0, 150, 0),
Vector3.Up);
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
aspectRatio,
10,
10000);
// Draw the tank model.
tank.Draw(rotation, view, projection);
// If the game is transitioning on or off, fade it out to black.
if (TransitionPosition > 0)
ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
base.Draw(gameTime);
}
}
}
#endregion
Please help. This error has been driving me mad!!