GraphicsDevice is null in my XNA Windows Game project

Posted by indyK1ng on Stack Overflow See other posts from Stack Overflow or by indyK1ng
Published on 2010-05-09T03:23:08Z Indexed on 2010/05/09 3:28 UTC
Read the original article Hit count: 327

Filed under:
|
|
|
|

Hello All,

I have just started trying to make a simple game with XNA 3.1 to help myself learn C# and XNA. I have run into a bit of an interesting problem, however. In all of the tutorials, one is supposed to pass GraphicsDevice when instantiating a new spriteBatch object like this:

spriteBatch = new SpriteBatch(GraphicsDevice);

One might even do this:

GraphicsDevice objGraphics = new graphics.GraphicsDevice;
spriteBatch = new SpriteBatch(objGraphics);

where graphics is the GraphicsDeviceManager. However, no matter which version I try, I always get an ArgumentNullException when I try to pass the GraphicsDevice object to spriteBatch's constructor. Almost every tutorial I have found gives the first one and only one mentioned the second option. Has anyone else run into a similar error or know what could be causing this? I am working in Windows 7 x64 with Visual Studio 2008.

© Stack Overflow or respective owner

Related posts about XNA

Related posts about c#