If I missed the answer to this question being already posted I apologize but I was unable to find it.

I'm new to C# and XNA and converting a VB game I created into them. Im finding a problem I'm not sure how to get around.

I'm using a generic list that contains information about nonplayer characters including the Graphic, Vector2, Rectangle. I'm reading this information from a file. So I have a class to receive all the information then I add it to the generic List. It then passes that information back to the main Game1.cs.

My problem is when it gets to the Draw method after loading all the information into the generic List<> the other methods in the main see the list EXCEPT the Draw and Update methods. I thought this would be because of the protected status of those methods but it will not let me change them to public.

So to sum up NPCClass.cs creates a class to accept the information. LoadLevel.cs reads from a text file and loads a instance of the NPCClass and adds it to a generic list of the NPCClass that is contained in the Game1.cs. The Draw Method in Game1.cs will not see the generic List even tho I have it publicly declared in Game1.cs main.

Thank you for any help and if i'm going at this completely incorrectly please don't hesitate to tell me.

  • 6
    \$\begingroup\$ Could you provide is with some code perhaps? Preferably all the relevant code and what files the code is in. \$\endgroup\$
    – William
    Dec 23, 2011 at 3:14
  • \$\begingroup\$ What is the error you are getting when trying to make the list public? Sounds like you might be defining the list as a local variable (inside a method) instead of a member variable (inside the class). \$\endgroup\$ Dec 23, 2011 at 16:59
  • \$\begingroup\$ Are you sure you declared the list in the correct scope of Game1.cs? Make sure you put it right under the namespace declaration (in that scope, anyways). \$\endgroup\$
    – DMan
    Dec 24, 2011 at 0:06

1 Answer 1


It sounds like you have built a class when what you want is a game component. A game component overloads the Game1.cs Draw and Update loops with the code contained in the component's draw and update loops. To create a component just right-click on your project and select ->Add New Item and then select game component from the XNA options.

You also may want to look at the XGPA tutorial series that shows how to build a 2D RPG from the ground up. Even if you don't want to follow all the tutorials you can download the lesson source code and see how the author built the project:


  • \$\begingroup\$ Or, alternatively, take the existing class and implement the "DrawableGameComponent" interface. Just be sure to override the draw and update methods, or nothing will happen. \$\endgroup\$ Jan 4, 2012 at 20:59
  • \$\begingroup\$ That's very much true. You would put :DrawableGameComponent after your class declaration. \$\endgroup\$
    – ChargerIIC
    Jan 4, 2012 at 21:07
  • \$\begingroup\$ Personally I have found it easier to not implement DrawableGameComponent for every single drawable object and instead just used it for rendering systems that hold a list of the objects and operate at a broader scope. Drawing the objects is more explicit and you have more control over their drawing order. \$\endgroup\$
    – ChrisC
    Jan 5, 2012 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .