我无法加载纹理我不知道为什么,因为我的代码很简单。
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);
}
}
}
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");
}
}
以下是例外细节:
System.ArgumentNullException未处理HResult = -2147467261
消息= La valeur ne peutpasêtrenull。 Nomduparamètre:图形 设备不能为空Source = MonoGame.Framework ParamName = Graphics 设备不能为空StackTrace: àMicrosoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice,Int32宽度,Int32高度,布尔mipmap, SurfaceFormat格式,SurfaceType类型,布尔共享,Int32 ARRAYSIZE) àMicrosoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice,Int32宽度,Int32高度) à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(对象状态) àSystem.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx) àSystem.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx) àSystem.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) àSystem.Threading.ThreadHelper.ThreadStart()InnerException:
感谢您的关注。
答案 0 :(得分:0)
我建议您在内容管理器准备好使用后加载您的内容。我不确定这是否可以解决您的问题,但对我来说这似乎是一个可能的问题。
这样做:
protected override void LoadContent()
{
Art.Load(Content);
}