-1
\$\begingroup\$

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");
    }
\$\endgroup\$
  • \$\begingroup\$ Does that class know something about Content class? Is it member of that class? In "default" Content is member of Game object. \$\endgroup\$ – zacharmarz Jul 11 '12 at 16:35
1
\$\begingroup\$

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");
}
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.