XNA project - who is responsible for drawing?

I just play with XNA and I have several different models that I need to draw in each frame. at the moment, the Game object contains links to all my models and draws them one by one. Each with its own way of drawing - one has two separate textures, and the other can be mirrored on the other side, etc.

I was wondering if you can just add

public void Draw(SpriteBatch spriteBatch)

for all my models (of course, from BaseModel), and each class is responsible for drawing on its own, or maybe I should ensure that the classes set their data in accordance with the events (KeyboardState) in the Update method, and save all the graphic logic in the class Game.

Is there a preferred way to do this?

+3
source share
2 answers

Typically, I have a base class that contains 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 the Draw method, which draws a model by default with texture, rotation, and scale data in the class. Derived classes can override it to attract an actor as they like.

Then I have a DrawableGameComponent that acts like my scene graph. It contains a list of all active objects of the actor. In the component drawing and updating methods, I repeat the list of participants and call them the drawing and updating methods.

+5
source

... . , , ( ) , . - ... .

... , . , , , , . "Entity"

  • VisualRepresentation
  • Entity [] AttachedEntities

"List<Entity>"

  • (.. )
  • AttachedEntities ().

, , ... , . (.. , , ​​..).

, , . , ... , , , , , , : -P

+3

Source: https://habr.com/ru/post/1706973/


All Articles