Marco
Marco

Reputation: 463

MonoGame: Cannot load assets

I started days ago programming c# using monogame. Today I got an error that says "Could not load asset as a non-content file". Here's the code, I need much help. List textures;

    public Game1()
        : base()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }
    protected override void Initialize()
    {
        base.Initialize();
    }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        // the below line errors
        textures.Add(Content.Load<Texture2D>("Lol"));

    }
    protected override void UnloadContent()
    {
    }
    protected override void Update(GameTime gameTime)
    {
        base.Update(gameTime);
    }
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        base.Draw(gameTime);
    }
}

Upvotes: 0

Views: 281

Answers (1)

Marco
Marco

Reputation: 463

SOLVED

  1. Create a sub-folder under the Content one.
  2. Call it "Assets"
  3. Right click on the image file and right click
  4. Properties -> Copy to Output -> Copy always
  5. Go to the main class and set the RootDirectory as "Content.RootDirectory = @"Content\Assets";"

P.s. : Everytime you add a file, repeat 3rd and 4th step

Upvotes: 1

Related Questions