为 Java 游戏生成简单的场景图
我正在使用 OPENGL (通过处理)用 Java 开发一个相对简单的游戏。我使用的是典型的 MVC 模式,其中游戏更新使用观察者模式传递到处理 Applet。我想实现一个相对简单的场景图,程序的模型端可以更新并且视图端可以读取。到目前为止一切都很好,但场景图对我来说是新的,我一开始就很难想出一种生成场景图的合适方法。
模型方面目前有两个游戏实体集合,一个用于游戏中的单位,另一个用于环境对象。我可以简单地迭代这些并生成节点以添加到场景图中。我不确定的是当这些实体之一被更改或破坏时该怎么办。我是否再次生成整个树(似乎效率很低),或者每个实体是否应该“知道”其场景节点并能够在需要时更新它?
有人对如何生成场景图有任何一般建议或材料链接吗?
I'm working on a relatively simple game in Java using OPENGL (via Processing). I'm using a typical MVC pattern with game updates being passed to the Processing Applet using an Observer pattern. I want to implement a relatively simple scene graph that the model side of the program can update and the view side can read. So far so good but scene graphs are new to me and I'm having trouble coming up with a decent way of generating the scene graph in the first place.
The model side has two collections for game entities at the moment, one for units in the game and a second for environmental objects. I could simply iterate through these and generate nodes to add to the scene graph. What I'm not sure about is what to do when one of these entities is changed or destroyed. Do I generate the entire tree again (seems pretty inefficient) or should each entity `know' its scene node and be able to update it when required?
Does anyone have any general advice or links to material on how to generate the scene graph?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,你必须在图形对象和游戏实体之间建立联系。因为否则您将无法将用户事件(例如鼠标单击)从场景转换为逻辑。
所以我建议引入模型和视图之间的连接。而且,恕我直言,不是通过创建一个完美的 MVC 来隐藏另一个 MVC,因为这会在开发的起始阶段增加太多麻烦。只需将图形对象的链接(或者更好的是,与您想要对图形执行的操作进行交互的界面)添加到游戏实体就应该适合您。
它可能如下所示:
You have to have a connection between graphical object and game entities anyway. Because otherwise you wouldn't be able to translate user event like mouse clicks from scene to logic.
So I would advise to introduce connection between your Model and View. And, IMHO, not by creating a perfect MVC with hiding one from other, as it would add too many hassle on starting stage of development. Just adding a link to graphical object (or, better, interface with actions you want to do with graphic) to game entity should work for you.
It can look like next: