0

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!

5
  • "However I can't find a way that works." Which ways have you tried? XNA: get screen's width and height? Feb 11, 2014 at 1:38
  • have you tried graphics.PresentationParameters.PreferredBackBufferWidth? (and height)
    – davidsbro
    Feb 11, 2014 at 1:40
  • Here i put on the code that i've tried Feb 11, 2014 at 2:12
  • What do you mean by "crash"?
    – davidsbro
    Feb 11, 2014 at 2:12
  • It goes back to the start screen and the game stops debugging Feb 11, 2014 at 2:13

1 Answer 1

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.