【问题标题】:How can i get the width and height of the screen in xna?如何在 xna 中获取屏幕的宽度和高度?
【发布时间】:2014-02-11 01:36:26
【问题描述】:

所以在我的 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;

谢谢!

【问题讨论】:

  • "但是我找不到可行的方法。" 您尝试过哪些方法? XNA: get screen's width and height?
  • 你试过graphics.PresentationParameters.PreferredBackBufferWidth吗? (和高度)
  • 这里放上我试过的代码
  • “崩溃”是什么意思?
  • 回到开始画面,游戏停止调试

标签: c# xna monogame


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2010-11-25
    • 2011-09-25
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 2011-06-12
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多