Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

well I have googled it and got some answers, asked many times, answered many times. as I read viewport is the "inside window" So I have 2 integers, height and width and this code:

        heightofwindow = graphicsDevice.Viewport.Bounds.Height;
        widtthofwindow = graphicsDevice.Viewport.Bounds.Width;

However, I get the error. It doesnt matter if I put it under update or draw. This seems like a more of language problem due to my limited knowlodge.

Object reference not set to an instance of an object.
share|improve this question
    
What's the error? –  William 'MindWorX' Mariager Aug 6 '12 at 0:23
    
"Object reference not set to an instance of an object." –  Newell Aug 6 '12 at 0:27
2  
graphicsDevice or Viewport or Bounds is null then –  indeed005 Aug 6 '12 at 0:49
    
@Newell, How do you initialize "graphicsDevice"? –  William 'MindWorX' Mariager Aug 6 '12 at 0:51
    
Well apperantly the incorrect way. It seems I've mistaken " GraphicsDeviceManager" for actual graphicsdevice. Can you tell me how can I init. it ? It seems it requires 3 parameters that I havent need until now. I think i can just init. last 2 class with no parameters but how do I init graphicsadapter ? –  Newell Aug 6 '12 at 1:32
add comment

1 Answer 1

up vote 0 down vote accepted

The graphics device manager is created in the game class constructor...

You should use the reference that provides the game instance to access to the GraphicsDevice

if you are inheriting from Game class... in your main class code you can use

this.GraphicsDevice.Bounds.Width/Height

if you are inheriting from GameComponent... in your component code you can use

this.Game.GraphicsDevice.Bounds.Width/Height
share|improve this answer
    
how do I init graphicsdevice ? I dont have/dont know how to init graphicsadapter. –  Newell Aug 6 '12 at 1:33
    
@Newell, when you create a new XNA game project, it does this for you in the generated Game1.cs. Check the constructor of Game1. –  Justin Skiles Aug 6 '12 at 2:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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