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.

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)
{
...
LoadContentAudio(content);
....
}

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
add comment

2 Answers

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
add comment

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
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.