2
\$\begingroup\$

I am trying to load up a single SpriteFont to print some debug information. In our current game, we load up both Textures and Music through a ResourceManager. They are both loaded with a filestream, and thus do not require Content.Load

SoundEffect soundEffect = SoundEffect.FromStream( fs );

Since this ResourceManager does not inherit from Game or is like Game.cs, I cannot use the usual method:

SpriteFont spriteFont = Content.Load<SpriteFont>(resource.Key.Item2);

Anyone have any idea how I can either: -Load the SpriteFont a different way -Create my own Contentmanager

\$\endgroup\$
  • 1
    \$\begingroup\$ Just send Content as parameter to the other class? This is generally how it's made. If you have a scene class(for example, not necessarily) you usually pass content (or entire game) as parameter to the class creator. So you can create your resources in there. \$\endgroup\$ – Gustavo Maciel Mar 21 '12 at 4:35
1
\$\begingroup\$

You could do what Gustavo - Gtoknu said and pass the content manager variable into your ResourceManager class OR you could create a new content manager. You'd have to have a reference to your main game class, but this is the idea:

ContentManager content = new ContentManager(myGameRef.Services, "Content");

Where "Content" is the root directory to load content from.

Keep in mind that when the content variable is disposed, so are all the resources associated with it (ie. anything you loaded), so you want to keep it in scope until you're done with the resources it loaded.

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