Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to implement a simple particle system in my XNA project. I'm going by RB Whitaker's tutorial, and it seems simple enough. I'm trying to draw particles within my menu screen. Below I've included the code which I think is applicable.

I'm coming up with one error in my build, and it is stating that I need to create a new instance of the EmitterLocation from the particleEngine. When I hover over particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); it states that particleEngine is returning a null value. What could be causing this?

/// <summary>
/// Base class for screens that contain a menu of options. The user can
/// move up and down to select an entry, or cancel to back out of the screen.
/// </summary>
abstract class MenuScreen : GameScreen

    ParticleEngine particleEngine;

    public void LoadContent(ContentManager content)
        if (content == null)
            content = new ContentManager(ScreenManager.Game.Services, "Content");
        List<Texture2D> textures = new List<Texture2D>();
        particleEngine = new ParticleEngine(textures, new Vector2(400, 240));


    public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                   bool coveredByOtherScreen)
        base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

        // Update each nested MenuEntry object.
        for (int i = 0; i < menuEntries.Count; i++)
            bool isSelected = IsActive && (i == selectedEntry);

            menuEntries[i].Update(this, isSelected, gameTime);

        particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X,      Mouse.GetState().Y);


    public override void Draw(GameTime gameTime)
        // make sure our entries are in the right place before we draw them

        GraphicsDevice graphics = ScreenManager.GraphicsDevice;
        SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
        SpriteFont font = ScreenManager.Font;


       // Draw stuff logic


share|improve this question
First, make sure that LoadContent is called, by printing a debug message or adding a breakpoint in the method. – William Mariager Jun 15 '12 at 0:12

you call to base.LoadContent() inside LoadContent and the method is not overrided.

Maybe adding the override tag and removing the content manager parameter will do the trick ...

public override void LoadContent()
share|improve this answer

I figured it out. Thanks guys, I learned a bit from your answers nonetheless.

I was trying to draw the particles in the wrong class. Instead of MenuScreen it should have been done in BackgroundScreen, which is where all of my Drawing is done for those screens.

share|improve this answer
I know you might not be able to yet, but when you are able, mark this as the correct answer. Thanks – John McDonald Jun 15 '12 at 18:42

I think we need to see more code. Is GameScreen from the state management sample? What should be calling LoadContent? Is it a DrawableGameComponent? Don't forget the override keyword in the LoadContent declaration, otherwise you're just hiding the member function.

share|improve this answer
Yes, it is the state management sample. I've also included a link to my Particle and Particle Engine classes to clarify: [link] – Dave Voyles Jun 15 '12 at 11:40

I'm not that knowledgeable about particles but don't you need to go ParticleEngine particleEngine = new ParticleEngine(); ? Try that, no guarantee that's the fix though.

share|improve this answer
oh wait no never mind I see it in the loadcontent. My bad :/ – user17125 Jun 15 '12 at 0:13

The only way that would be the case would be if LoadContent was never invoked. Looks like you probably want to double check the screen manager that you're using to make sure that it's going to call LoadContent before ever calling Update

share|improve this answer
How can I make sure that Load Content is being called before update? – Dave Voyles Jun 15 '12 at 11:44

Your Answer


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.