1

hi there im a novice i have been creating the menu navigation for a game im going to make and ran into this pesky error message i know it will be a simple problem but for the life of me i can't see it ill post the code below

namespace Platformer
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Screen_Manager.Instance.Initiaize();

            Screen_Manager.Instance.Dimensions = new Vector2(800, 600);
            graphics.PreferredBackBufferWidth = (int)Screen_Manager.Instance.Dimensions.X;
            graphics.PreferredBackBufferHeight = (int)Screen_Manager.Instance.Dimensions.Y;
            graphics.ApplyChanges();



            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Screen_Manager.Instance.LoadContent(Content);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here

        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            Screen_Manager.Instance.Update(gameTime);
            base.Update(gameTime);


        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);


            spriteBatch.Begin();
            Screen_Manager.Instance.Draw(spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

 namespace Platformer
{
    public class Screen_Manager
    {

        #region variables

        ContentManager content;                     //  creating custom ContentManger

        Game_Screen currentScreen;                  // screen being currently displayed

        Game_Screen newScreen;                      // new screen taking effect

        private static Screen_Manager instance;     // Screen Manger instance


       // Dictionary<string, Game_Screen> screens = new Dictionary<string, Game_Screen>();     // Game Screen storage




        Stack<Game_Screen> screenStack = new Stack<Game_Screen>();                           // lets me know order of screens Stack


        Vector2 dimensions;                                                                  // width&Height of Screens  

        #endregion

        #region Properties

        public static Screen_Manager Instance
        {
            get
            {
                if (instance == null)
                    instance = new Screen_Manager();
                return instance;
            }
        }

        public Vector2 Dimensions
        { 
            get { return dimensions; }
            set { dimensions = value; }
        }


        #endregion

        #region Main Methods

        public void AddScreen(Game_Screen screen)
        {
            newScreen = screen;
            screenStack.Push(screen);
            currentScreen.UnloadContent();
            currentScreen = newScreen;
            currentScreen.LoadContent(content);
        }

        public void Initiaize() 
        {
            currentScreen = new Splash_Screen();
        }

        public void LoadContent(ContentManager Content) 
        {
            content = new ContentManager(Content.ServiceProvider, "Content");
            currentScreen.LoadContent(Content);
        }

        public virtual void Update(GameTime gameTime)
        {
              currentScreen.Update(gameTime);
        }

        public virtual void Draw(SpriteBatch spriteBatch) 
        { 
            currentScreen.Draw(spriteBatch);
        }

        #endregion


    }
}

namespace Platformer
{
    public class Game_Screen
    {
        protected ContentManager content;

        public virtual void LoadContent(ContentManager Content) 
        {
            content = new ContentManager(Content.ServiceProvider, "content");
        }

        public virtual void UnloadContent() 
        {
            content.Unload();
        }

        public virtual void Update(GameTime gameTime) 
        { 

        }

        public virtual void Draw(SpriteBatch spriteBatch) 
        { 

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Platformer
{
    public class Splash_Screen : Game_Screen
    {
        KeyboardState keystate;
        SpriteFont font;

        public override void LoadContent(ContentManager Content)
        {
            base.LoadContent(Content);
            if (font == null)
            font = content.Load<SpriteFont>("Font1");
        }

        public override void UnLoadContent()
        {
            base.UnloadContent();
        }

         public override void Update(GameTime gameTime)
         {
             keystate = Keyboard.GetState();
             if (keystate.IsKeyDown(Keys.Z))
                 Screen_Manager.Instance.AddScreen(new Title_Screen());
         }

         public override void Draw(SpriteBatch spriteBatch)
         {
             spriteBatch.DrawString(font, "SplashScreen",
                 new Vector2(100, 100), Color.Black);
         }

    }
}
namespace Platformer
{
    public class Title_Screen : Game_Screen
    {
        KeyboardState keystate;
        SpriteFont font;

        public override void LoadContent(ContentManager Content)
        {
            base.LoadContent(Content);
            if (font == null)
                font = content.Load<SpriteFont>("Font1");
        }

        public override void UnLoadcontent()
        {
            base.UnloadContent();
        }

        public override void Update(GameTime gameTime)
        {
            keystate = Keyboard.GetState();
            if (keystate.IsKeyDown(Keys.Enter))
                Screen_Manager.Instance.AddScreen(new Splash_Screen());
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, "Title Screen",
                new Vector2(100, 100), Color.Black);
        }

    }
}
Scott
  • 31
  • 1
  • 4
  • Do you understand `override`? – Jesse Good Aug 23 '14 at 07:57
  • Just in case: [msdn page](http://msdn.microsoft.com/en-us/library/ebca9ah3.aspx) for override :) – Noctis Aug 23 '14 at 08:00
  • [no suitable method found to override c#](http://stackoverflow.com/questions/9458572/no-suitable-method-found-to-override-c-sharp) and [difference between override and overload](http://stackoverflow.com/questions/673721/overloading-and-overriding) – Eugene Podskal Aug 23 '14 at 08:03
  • yes i understand override i uploaded all the code if anyone cares to take a crack and spot what will be a really obvious mistake im missing – Scott Aug 23 '14 at 08:20
  • Error 1 'Platformer.Splash_Screen.UnLoadContent()': no suitable method found to override and Error 2 'Platformer.Title_Screen.UnLoadcontent()': no suitable method found to override – Scott Aug 23 '14 at 08:26
  • @Scott: You made a trivial mistake. C# is case-sensitive (compare method names carefully). – Jesse Good Aug 23 '14 at 22:02

1 Answers1

3

The error is pretty simple to solve, you have this method in your Game_Screen class:

public virtual void UnloadContent() 
{
    content.Unload();
}

And then in both the Splash_Screen and Title_Screen classes you have this:

public override void UnLoadcontent()
{
    base.UnloadContent();
}

Check the name of the method!

You are trying to override UnloadContent with UnLoadcontent. This will never work as the name of the method is different, change the casing of the "L" in "Load" and you will be fine.

This is because if you override something, then the signature of the method has to be exactly the same as declared on the parent class, no matter what goes inside the method itself.

Nahuel Ianni
  • 3,177
  • 4
  • 23
  • 30
  • 1
    Thank you so much i always do stupid mistakes like these i just spent an hour trying to solve it. thanks again – Scott Aug 24 '14 at 09:54