如何在xna中获得屏幕的宽度和高度?

时间:2014-02-11 01:36:27

标签: c# xna monogame

所以在我的2d塔防游戏中,我需要获得屏幕的分辨率,以便在我的缩放矩阵中使用。但是我找不到一种有效的方法。我试过了:

_graphics.GraphicsDevice.Viewport.Width

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width

//It always crashes the game
_graphics.PreferredBackBufferWidth
//Also crashes

这是我的确切代码

screenscalex = (float) *whatever i put here* / 1366f;

谢谢!

1 个答案:

答案 0 :(得分:2)

确保在调用initialize后进行这些检查。在检查这些项目之前,必须初始化图形设备。

相关问题