2014-02-11 122 views
0

所以在我的2D塔防遊戲中,我需要獲得屏幕的分辨率,以便在縮放矩陣中使用。但是我找不到一種可行的方法。我已經試過:如何獲得xna屏幕的寬度和高度?

_graphics.GraphicsDevice.Viewport.Width 

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width 

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

這是我確切的代碼

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

謝謝!

+0

「*但是我找不到一個可行的方法。*」您嘗試過哪些方法? [XNA:獲取屏幕的寬度和高度](http://stackoverflow.com/questions/1377524/xna-get-screens-width-and-height)? –

+0

你嘗試過'graphics.PresentationParameters.PreferredBackBufferWidth'嗎? (和高度) – davidsbro

+0

在這裏,我把我試過的代碼 – Detinator10

回答

2

確保在調用initialize後執行這些檢查。在檢查這些項目之前,圖形設備必須被初始化。

相關問題