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 use this in the beginning of the class:

SoundEffect bangSound;

And then in the constructor I use this code:

bangSound = Content.Load<SoundEffect>("Sounds/bang");

But I get a red line under the Content, and I can't understand what is wrong? Help is preciated! Thanks!

EDIT: I solved it like this:

public Asteroid(ContentManager content, string textureName, Vector2 position)

With content I can then load the sound like this:

    public void LoadContentAudio(ContentManager content)
        bangSound = content.Load<SoundEffect>("Sounds/bang");
share|improve this question
Does that class know something about Content class? Is it member of that class? In "default" Content is member of Game object. – zacharmarz Jul 11 '12 at 16:35

I think you should load your content in the LoadContent() method. If you don't have this method in your derived game class, create a method that looks like this:

public override void LoadContent()
    bangSound = Content.Load<SoundEffect>("Sounds/bang");
share|improve this answer

Note that your class will need to derive from one of the XNA classes (GameObject or somesuch). Otherwise as John said above, you'll get errors.

If you simply created a class and added the XNA using statements, that isn't enough, it won't know about the static Content object.

share|improve this answer

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.