如何在 xna 中制作 类 - C#
How to make classes in xna - C#
我在 XNA(和 monogame)中编写 class 时遇到问题。我做了一个 class 来解决动画问题,但是每当我编译它时,我都会得到类似这样的错误:No graphics device manager found
。试图在 struct
中做同样的事情,但我收到如下错误:An unhandled exception of type 'System.NullReferenceException' occurred in app.exe
.
我做错了什么?
System.NullReferenceException 将是空对象的例外,这意味着您没有 "newed" 您的 类 之一的实例。调试器应该提供更详细的信息。
未找到图形设备管理器。如果没有看到您的代码,我不确定,但这可能意味着您完全遗漏了图形对象引用,忘记了初始化。 Microsoft 在其官方 msdn 上有一些示例。
当你像这样在Draw函数中引用它时:
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
首先必须这样创建:
GraphicsDeviceManager graphics;
并像这样初始化:
graphics = new GraphicsDeviceManager(this);
我在 XNA(和 monogame)中编写 class 时遇到问题。我做了一个 class 来解决动画问题,但是每当我编译它时,我都会得到类似这样的错误:No graphics device manager found
。试图在 struct
中做同样的事情,但我收到如下错误:An unhandled exception of type 'System.NullReferenceException' occurred in app.exe
.
我做错了什么?
System.NullReferenceException 将是空对象的例外,这意味着您没有 "newed" 您的 类 之一的实例。调试器应该提供更详细的信息。
未找到图形设备管理器。如果没有看到您的代码,我不确定,但这可能意味着您完全遗漏了图形对象引用,忘记了初始化。 Microsoft 在其官方 msdn 上有一些示例。
当你像这样在Draw函数中引用它时:
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
首先必须这样创建:
GraphicsDeviceManager graphics;
并像这样初始化:
graphics = new GraphicsDeviceManager(this);