tags:

views:

270

answers:

2

I am just playing around with XNA, and I have several different models I need to draw in each frame. at the moment, the Game object holds references to all my models, and draws them one after the other. Each with his own different way of drawing - one has two separate textures, the other might be mirrored to the other side, etc.

I was wondering if it is acceptable to just add a

public void Draw(SpriteBatch spriteBatch)

method to all my models (from the BaseModel, of course), and have each class be in charge of drawing itself, or maybe I should stick to letting the classes set their data according to events (KeyboardState) on the Update method, and keep all graphic logic in the Game class.

Is there a preferred way to do this?

+2  A: 

Generally, I have a base class that contains a BaseModel, texture data, rotation and scale data, etc. For each type of actor in the game, I create a derived class. The base class provides a Draw method that, by default, draws the model with the texture, rotation, and scale data given in the class. Derived classes can override it to draw the actor however they like.

Then, I have a DrawableGameComponent that acts as my scene graph. It contains a list of all active actor objects. In the component's Draw and Update methods, I iterate through the list of actors and call their Draw and Update methods.

David Brown
A: 
Joel Martinez
Thanks for the other view on things
Noam Gal