Как исправить ошибку «Не найдено подходящего метода для переопределения» в XNA 4.0? - PullRequest
1 голос
/ 15 ноября 2011

Я следую по уроку "Дорога не пройдена" , но я получаю ошибку No suitable mthod found to override.Вот мой проект XNA:

Код

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    SpriteBatch mSpriteBatch;
    Texture2D mTrack;

    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()
    {

        //Change the resolution to 800x600
        graphics.PreferredBackBufferWidth = 800;
        graphics.PreferredBackBufferHeight = 600;
        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 LoadGraphicsContent(bool loadAllContent)
    {
        if (loadAllContent)
        {
            //Create the SpriteBatch used for drawing the Sprites
            mSpriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            //Load the images from computer into the Texture2D objects
            mTrack = Content.Load<Texture2D>("Track");
        }
        // TODO: use this.Content to load your game content here
    }

    /// <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();

        // TODO: Add your update logic here

        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);

        // TODO: Add your drawing code here

        mSpriteBatch.Begin();

        mSpriteBatch.Draw(mTrack, 
                          new Rectangle(0, 0, mTrack.Width, mTrack.Height),
                          Color.White);

        mSpriteBatch.End();

        base.Draw(gameTime);
    }
  }
}

Ошибка

TheRoadNotTaken.Game1.LoadGraphicsContent(bool)': no suitable method found to override

Как я могу исправить эту ошибку?

1 Ответ

2 голосов
/ 15 ноября 2011

Я считаю, что LoadGraphicsContent устарела.Вам нужно переопределить LoadContent() вместо LoadGraphicsContent(bool loadAllContent)

Если этот учебник предназначен для 4.0, то он использует устаревшую информацию.Вот MSDN для этого: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.loadgraphicscontent(v=xnagamestudio.31).aspx

...