开发者

XNA - Using Game Components

When sh开发者_C百科ould one use Game Components? What are they used for, what is the design pattern around them?

Which is better:

  • Having a background component, a player component, a spaceship component and various instances of an enemy component, each one responsible for updating and drawing itself;

  • Having all of the above inside the gameplay screen class, which manages everything.

Speaking of gameplay screen, the game state management example didn't seem very modular. Is it better to structure things like in the example, where we program entire screens at once instead of reusable bits and pieces, or to use game components to achieve maximum modularity?


From MSDN:

Game components provide a modular way of adding functionality to a game. You create a game component by deriving the new component either from the GameComponent class, or, if the component loads and draws graphics content, from the DrawableGameComponent class. You then add game logic and rendering code to the game component by overriding GameComponent.Update,DrawableGameComponent.Draw and GameComponent.Initialize. A game component is registered with a game by passing the component to Game.Components.Add. A registered component will have its draw, update, and initialize methods called from the Game.Initialize, Game.Update, and Game.Draw methods.

Talking of the example, it is good practice to seperate your components into seperate classes. This will make it a lot easier to manage as your project gets bigger.

Here is another link with more information about the GameComponent and how/when to use them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜