XNA Creators Club Online
Page 1 of 1 (10 items)
Sort Posts: Previous Next

Problem Creating Menu

Last post 2/11/2008 4:46 PM by Jim Perry. 9 replies.
  • 2/8/2008 11:28 AM

    Problem Creating Menu

    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!!

  • 2/8/2008 12:30 PM In reply to

    Re: Problem Creating Menu

    Hi,

    try public instead of protected for LoadGraphicsContent. Check GameScreen.cs if the line public virtual void LoadGraphicsContent() {} exists. In the sample for XNA 2.0 it was changed to public virtual void LoadContent() {}.

    Michael

  • 2/11/2008 5:57 AM In reply to

    Re: Problem Creating Menu

    Hi,

    I tried public instead of protected but it still gives me the same error.

    Check the GameScreen.cs and it is changed

    Please help!
  • 2/11/2008 8:16 AM In reply to

    Re: Problem Creating Menu

    Hi,

    if the method in GameScreen.cs is called LoadContent(), you have to rename LoadGraphicsContent(bool loadAllContent) in your GameplayScreen class (where you marked the error) into LoadContent().

    It should look like this:

    public override void LoadContent()
    {
    tank.Load(Content);
    }

    Regards,

    Michael

  • 2/11/2008 8:55 AM In reply to

    Re: Problem Creating Menu

    Hi Michael,

    Thanks for that, it worked!!

    Unfortuntaly I am getting another three errors that say:
    1. The best overloaded method match for 'Microsoft.Xna.Framework.GraphicsDeviceManager.GraphicsDeviceManager(Microsoft.Xna.Framework.Game)' has some invalid arguments

    2. Argument '1': cannot convert from 'GameStateManagement.GameplayScreen' to 'Microsoft.Xna.Framework.Game'  

    3. The name 'Services' does not exist in the current context 


    They are coming in under the GameplayScreen class:

    public GameplayScreen()
            {
                graphics = new 1. GraphicsDeviceManager 2.(this);
                content = new ContentManager 3. (Services);
                content.RootDirectory = "Content";
                TransitionOnTime = TimeSpan.FromSeconds(1.5);
                TransitionOffTime = TimeSpan.FromSeconds(0.5);

                graphics.PreferredBackBufferWidth = 853;
                graphics.PreferredBackBufferHeight = 480;

                tank = new Tank();
            } 

    Thanks for your time!

    Nicole
      

  • 2/11/2008 9:31 AM In reply to

    Re: Problem Creating Menu

    Try changing the lines to:

    graphics = new GraphicsDeviceManager(this.Game);
    content = new ContentManager(this.Game.Services);

    You might have to case the Game member to the base Game class.

    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 2/11/2008 9:36 AM In reply to

    Re: Problem Creating Menu

    Ok I changed the lines but what do u mean by:

    You might have to case the Game member to the base Game class

    Sorry for not understanding
  • 2/11/2008 1:27 PM In reply to

    Re: Problem Creating Menu

    Hi,

    the base Game class is held in ScreenManager class because it derives from DrawableGameComponent (if you use the complete GameStateManagement sample).

    Instead of this.Game use Screenmanager.Game for these two lines.

    I think, Machaira meant that.

    Regards

    Michael

  • 2/11/2008 3:47 PM In reply to

    Re: Problem Creating Menu

    I'm completely new to XNA but not to C#.

    I'm pretty sure Machaira meant "Cast".

    If this is true, don't bother casting those objects to their base types unless you run into an issue with it.  It may or may not be necessary.

  • 2/11/2008 4:46 PM In reply to

    Re: Problem Creating Menu

    lmcfarlin:

    I'm completely new to XNA but not to C#.

    I'm pretty sure Machaira meant "Cast".

    If this is true, don't bother casting those objects to their base types unless you run into an issue with it.  It may or may not be necessary.

    Exactly. :)

    Didn't look at the post after posting it and missed the typo. :(

    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
Page 1 of 1 (10 items) Previous Next