Viewport Width returns null - Why?

I am trying to do some basic collision with some sprites. Left side of the screen is fine and dandy you can just use 0. The right side of the screen has proven to be a bit more difficult. With a set resolution I could just hard code the resolution but that won’t be useful for everyone. I have tried to get the screen width using the GraphicsDevice.Viewport.Width; property. However, the property returns to me null ;

  • Inside LoadContent() , I initialise an object of Game1 to access GraphicsDevice and set a member variable to Graphics.Device.Viewport.Width. The member variable is = 0 or null.

I have a feeling it’s because you call LoadContent from the Game1 Initialise function. I think the GraphicsDevice gets set up in Base.Initialise so hasn’t been set up yet. You’ve commented out the LoadContent in the proper Game1.LoadContent function which is really where it should be called.