Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:56:30+00:00 2026-05-14T20:56:30+00:00

I have just started trying to make a simple game with XNA 3.1 to

  • 0

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.

EDIT:

I seem to have found the problem. I was trying to execute that code in the constructor (which is where I assumed it was supposed to go). I did a bit of Googling and found the answer here. Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:56:31+00:00Added an answer on May 14, 2026 at 8:56 pm

    I’m putting the answer here for completeness’ sake.

    The code

    spriteBatch = new SpriteBatch(GraphicsDevice);
    

    Can only be executed in the LoadContent() method of the Game class. I was putting it in the constructor at which point the GraphicsDevice object has not been defined according to one of the answers to this question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to make a little simple game just to test my logics,
I have just started developing in Android and I am trying to make a
I have just started learning Erlang and am trying out some Project Euler problems
I am trying to make a simple game that goes across a TCP network.
I'll try to make this as simple a posible. I just started working with
I am trying to make the game Asteroids. My issue I have right now,
I've just started developing a hobby site for myself, and trying to use the
I just started messing around with C#/.NET/mono and stuff, and I'm trying to make
I have just started looking at javascript so hopefully this will be something simple.
Have just started using Google Chrome , and noticed in parts of our site,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.