【发布时间】:2015-06-01 14:59:59
【问题描述】:
我不知道为什么我无法加载纹理,因为我的代码非常简单。
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
Message=La valeur ne peut pas être null。 Nom du paramètre : 图形 设备不能为空 Source=MonoGame.Framework ParamName=Graphics 设备不能为空 StackTrace: à Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height, Boolean mipmap, SurfaceFormat 格式,SurfaceType 类型,布尔共享,Int32 数组大小) à Microsoft.Xna.Framework.Graphics.Texture2D..ctor(GraphicsDevice graphicsDevice,Int32 宽度,Int32 高度) à Microsoft.Xna.Framework.Graphics.Texture2D.PlatformFromStream(GraphicsDevice graphicsDevice,流流) à Microsoft.Xna.Framework.Graphics.Texture2D.FromStream(GraphicsDevice graphicsDevice,流流) à Microsoft.Xna.Framework.Content.ContentManager.ReadRawAsset[T](字符串 资产名称,字符串原始资产名称) à Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String 资产名称,Action`1 记录DisposableObject) à Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetsName) à Rogue_Like_LOL.Art.Load(ContentManager content) dans c:\Users\Monique Dumont\Programmation\Rogue Like LOL\Rogue Like 大声笑\艺术经理\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 程序集,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 回调、对象状态、布尔值 保留SyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean 保留SyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart() InnerException:
感谢您的关注。
【问题讨论】:
-
您的纹理在“内容”中,对吗?不在任何子文件夹中?
-
@DavorMlinaric 是的,当然,我还检查了 .png 是否在“始终复制”上。
-
内容应该在
LoadContent(更合适)或InitializeGame1 的虚拟方法中通过覆盖其中任何一个来加载。请注意,在覆盖 Initialize 时,请确保调用base.Initialize(),因为这实际上是在初始化基本游戏系统。