开发者

Which of these choices is the better design for drawing objects?

What would be a better parctice, writing the drawing metho开发者_如何学Cd inside the GameObject class or in the Game class?

GameObject obj = new GameObject();
obj.Draw();

Or

GameObject obj = new GameObject();
DrawGameObject(obj);


It depends on what Game and GameObject are responsible for. Typically, a GameObject would contain all the information about what to draw -- it'd have a model, for instance. But objects aren't independent of each other -- knowing what to draw isn't sufficient to know how to draw it.

So a Game probably knows a lot more than a GameObject. In particular, it might know:

  • whether or not a particular object should be drawn (e.g. it's occluded based on the current camera)
  • how to draw a particular object (shadows from other objects; reflections from nearby surfaces; ambient light factors; etc.)
  • etc.

Of the two options presented, it probably makes more sense to put the Draw method outside the GameObject.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜