0
votes

I can't load textures I don't know why since my code is pretty straightforward.

namespace Rogue_Like_LOL
{
    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;
        ScreenManager screenManager;

        public Game1()
            :base()
        {

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;
            Content.RootDirectory = "Content";

            Art.Load(Content);
        }
    }
}

And the Art.cs :

    namespace Rogue_Like_LOL
    {
        static class Art
        {
            public static Texture2D Player { get; private set; }
            public static Texture2D PlayGame { get; private set; }
            public static Texture2D Exit { get; private set; }

            public static SpriteFont GameFont { get; private set; }

            public static void Load(ContentManager content)
            {
                // Player etc
                PlayGame = content.Load<Texture2D>("playgame");
                Exit = content.Load<Texture2D>("exit");

            }

    }

Here are the Exception details :

System.ArgumentNullException was unhandled HResult=-2147467261
Message=La valeur ne peut pas être null. Nom du paramètre : Graphics Device Cannot Be Null Source=MonoGame.Framework ParamName=Graphics Device Cannot Be Null StackTrace: à Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height, Boolean mipmap, SurfaceFormat format, SurfaceType type, Boolean shared, Int32 arraySize) à Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height) à Microsoft.Xna.Framework.Graphics.Texture2D.PlatformFromStream(GraphicsDevice graphicsDevice, Stream stream) à Microsoft.Xna.Framework.Graphics.Texture2D.FromStream(GraphicsDevice graphicsDevice, Stream stream) à Microsoft.Xna.Framework.Content.ContentManager.ReadRawAsset[T](String assetName, String originalAssetName) à Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject) à Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) à Rogue_Like_LOL.Art.Load(ContentManager content) dans c:\Users\Monique Dumont\Programmation\Rogue Like LOL\Rogue Like LOL\Art Manager\Art.cs:ligne 22 à Rogue_Like_LOL.Game1..ctor() dans c:\Users\Monique Dumont\Programmation\Rogue Like LOL\Rogue Like LOL\Game1.cs:ligne 34 à Rogue_Like_LOL.Program.Main() dans c:\Users\Monique Dumont\Programmation\Rogue Like LOL\Rogue Like LOL\Program.cs:ligne 17 à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() à System.Threading.ThreadHelper.ThreadStart_Context(Object state) à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart() InnerException:

Thanks for your attention.

1
your textures are in "Content" right? not in any subfolder?Davor Mlinaric
@DavorMlinaric Yes of course, I also checked if the .png were on "Copy always".MoniqueDumont
Content should be loaded either in LoadContent (more appropriate) or Initialize virtual methods of Game1 by overriding either of these. Note that when overriding Initialize, make sure to call base.Initialize() because that is what is actually initializing base game systems.Jaanus Varus

1 Answers

0
votes

I suggest you to load your content after the content manager is ready to be used. I am not sure if this would solve your problem, but it seems like a possible issue to me.

To do so:

protected override void LoadContent()
{
    Art.Load(Content);
}