Detinator10
Detinator10

Reputation: 123

How can i get the width and height of the screen in xna?

So in my 2d tower defense game I need to get the resolution of the screen for use in my scaling matrix. However I can't find a way that works. I've tried:

_graphics.GraphicsDevice.Viewport.Width

and

GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width

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

THis is my exact code

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

Thank you!

Upvotes: 0

Views: 516

Answers (1)

willthiswork89
willthiswork89

Reputation: 617

Make sure you are doing these checks after initialize is called. the graphics device must be initialized before checking these items.

Upvotes: 2

Related Questions