我的班级中的 GraphicsDeviceManager 对象(帖子中有更好的解释)
好吧,所以我有一个 GameObject 类(我自己制作),我想创建一个包含屏幕最大宽度的 GraphicsWidth 变量,这意味着我需要创建一个 GraphicsDeviceManager 实例。 (正确的?)。好吧,这就是我所做的:
protected GraphicsDeviceManager GM;
public int GraphicsWidth
{
get
{
return GM.GraphicsDevice.Viewport.TitleSafeArea.Width;
}
}
它说我需要使用“new”(初始化对象)。但我不知道如何从我的 GameObject 类中做到这一点?
拜托拜托拜托,有人可以帮我吗?真的很感激。 谢谢。
编辑:有人可以吗?
Alright, so I have a GameObject class (I made by myself) and I wanted to create a for example GraphicsWidth variable that contains the Maximum width of the screen, it means I need to create a GraphicsDeviceManager instance. (Right?). Alright, this is what I did:
protected GraphicsDeviceManager GM;
public int GraphicsWidth
{
get
{
return GM.GraphicsDevice.Viewport.TitleSafeArea.Width;
}
}
And it says that I need to use the "new"(initialize the object). But I don't know how can I do that from my GameObject class?
Please please please, can anyone help me with this? Really appriciated.
Thanks.
EDIT: Anyone please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GraphicsDeviceManager 在您的 Game1 类中实例化。最有可能的是,您也在 Game1 类中实例化了 gameObject。当您实例化您的游戏对象时,传递一个 GraphicDeviceManager 的引用:
或者... 与上面相同,但传递服务,以便您可以使用它包含的任何内容。
或者...以相同的方式传递游戏引用。我看到很多人都这样做。
或者...将graphicsDeviceManager设为静态,因为只有一个。
我通常传递服务容器引用,但大多数人传递游戏引用。有些人只将引用传递给 GameObject 类中实际需要它的方法。
The GraphicsDeviceManager is instantiated in your Game1 class. Most likely, you are also instantiating your gameObject in your Game1 class too. When you instantiate your gameObject, pass a reference of the graphicDeviceManager with it:
Or... Do the same as above but pass along the Services so you can use anything it contains.
Or... pass the Game reference along the same way. I see lots of people do that.
Or... Make the graphicsDeviceManager static since there will only be one.
I usually pass the service container ref but most people pass the game ref. Some people pass the reference only to the method in the GameObject class that actually needs it.