Take the 2-minute tour ×

I have created a separate class (let's call it class2.cs for example) and want to use it as a level, in that when I call it, it will draw everything in one level for me. I'm having trouble getting contentmanager to work in class2. In the given Game1.cs, you can easily just go texture2d= Content.Load<Texture2D>("photo"); but I can't in class2.

I realize I have to create a new Content Manager, but it's constructor requires a game service, in which I'm not sure what I'm suppose to plug in. I currently have: ContentManager content = new ContentManager(); but I need an overload for ContentManager.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Pass Content to the constructor of your second class from the game, or you can create a Globals.cs class with static variables for your ContentManager or spriteBatch or any common resources.

share|improve this answer
Do not use globals - use dependency injection instead (codeplex.com/unity) –  BlueRaja - Danny Pflughoeft Mar 6 '10 at 3:25
EDIT: Never mind fixed, I had to load contentmanager after initialize, not as in the constructor. –  DMan Mar 6 '10 at 4:10
@BlueRaja, "pass Content to the constructor of your second class", that is dependency injection, btw –  Allen Rice Mar 9 '10 at 15:30
add comment

Your Answer


