开发者

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

开发者 https://www.devze.com 2022-12-25 05:19 出处:网络
What would be a better parctice, writing the drawing metho开发者_如何学Cd inside the GameObject class or in the Game class?

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

精彩评论

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

关注公众号