OOP游戏设计理论

发布于 2024-08-16 11:21:19 字数 133 浏览 2 评论 0原文

我过去曾尝试使用 C++ 仅仅使用对象来开发 2D 游戏,但是,在设计过程中,我不知道应该如何以及引擎的哪些部分分割成更小的对象,它们究竟应该做什么以及如何进行使他们能够正确地互动。我正在寻找书籍、教程、论文以及任何能详细解释游戏引擎设计的东西。谢谢。

I've tried to develop a 2D game with C++ in the past using mere objects, however, in the design process I don't know how and what parts of the engine I should split into smaller objects, what exactly they should do and how to make them interact with each other properly. I'm looking for books, tutorials, papers, anything that explains the game engine design in detail. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情释 2024-08-23 11:21:19

必读:http://scientificninja.com/advice/write-games-not-engines< /a>

您认为为什么需要游戏引擎?编写实现游戏所需的代码。随着需求的变化不断修改它。当你完成一个完整的游戏后,退后一步看看结果是什么样的。

您不能也不应该在一开始就布置出完整的类图。勾画出您想要的通用组件以及它们的职责应该是什么的粗略想法,然后尝试对其进行编码。从您确定的课程开始。迟早,其中一些会变得庞大且难以操作,因此您将其分成多个较小的。有时,您可能会发现几个类基本上在做相同的事情,因此您将它们合并在一起。希望您迟早会得到一个有效的设计,这比您尝试预先设计游戏引擎时获得的效果要好得多。

Mandatory reading: http://scientificninja.com/advice/write-games-not-engines

Why do you think you need a game engine? Write the code you need in order to implement your game. Modify it along the way as requirements change. And when you have a complete game, take a step back and look at what the result looks like.

You can't, and shouldn't, lay out a complete class diagram at the start. Sketch out a rough idea of what general components you want, and what their responsibilities should be, and then try to code it. Start out with the classes you're sure of. Sooner or later, some of them will get big and unwieldy, so you split it into multiple smaller ones. Sometimes, you may find that several classes are basically doing the same thing, so you merge them back together. Hopefully, sooner or later, you'll end up with a design that works, which is more than you'd get if you tried to design a game engine up front.

错々过的事 2024-08-23 11:21:19

如果你以前没有制作过游戏,怎么能制作引擎呢?那里有大量的免费引擎,否则您将花费​​ 20 年的时间来尝试完成某件事,因为您将一遍又一遍地重写。

If you haven't made a game before, how can you make an engine? There's tons of free engines out there or you will be spending 20 years trying to get something done because you will be rewriting over and over again.

酒废 2024-08-23 11:21:19

游戏中有两种重要的对象类型。有些对象包含进程,有些对象与环境和用户交互。

对于那些运行诸如更改对象的不透明度之类的过程的对象,您将希望它们独立于任何类级别变量。他们应该简单地接受值并返回值。如果您有一个计算重力的过程,则该过程应该接收正在计算重力的对象,并返回该对象所承受的重力大小,如果游戏发生在太空中,则返回重力方向。

第二个更重要的对象类型是那些与用户和环境交互的对象。这些对象应该全部继承于同一个基类。基类需要图像以及 x 和 y 位置,并且可以具有执行特定过程(例如更改变量的速度或方向)的变量。
有了这个基类,您就可以使用每个对象的“内置”变量(例如速度、方向以及 x 和 y 位置)执行前面提到的重力过程之类的过程。

您还需要设置对象以在特定条件下运行代码片段。让基类提供在满足这些条件之一时运行的函数可能是个好主意。一些有用的条件函数是在首次创建对象和销毁对象时使用的条件函数。设置计时器后执行的条件函数。一个持续运行的条件函数,您可以在其中放置代码以在屏幕上绘制图像。当按下键盘或鼠标按钮时关闭的条件功能。每秒执行一定次数的条件函数,用于计算物体上的重力等内容。

这个框架在我创建游戏时非常有效。它适用于任何类型的游戏,并且适用于其他类型的程序。抱歉,如果我的文字不清楚,我正在 iPod 上打字,我很难回去编辑这里的内容。

There are two important types of objects in a game. There are objects that contain processes, and there are objects that interact with the environment and the user.

For those objects that run a process like changing the opacity of objects you'll want them to be independant of any class level variables. They should simply take in value(s) and return value(s). If you have a process to calculate gravity, the process should take in the object that it gravity is being calculated on, and return the the amount of gravity that the object is experiencing, and the direction of gravity if the game takes place in space.

The second more important types of objects are those that interact with the user and the environment. These objects should all inheret of the same base class. The base class will require an image, and the x and y position, and can have variables that perform specific processes like changing the speed or direction of the variable.
With this base class in place you can then perform proccesses like the gravity proccess mentioned earlier using every objects "built-in" variables like speed, direction, and x and y position.

You will also want to set up your objects to run peices of code under certain conditions. It may be a good idea to have your base class provide functions that get run when one of these conditions are met. Some useful conditional functions are a conditional function to go of when an object is first created and when it is destroyed. A conditional function to go of after a timer is set. A conditional functional to go of continually where you can place code to draw images on the screen. A conditional function to go off When a keyboard or mouse button is pushed. A conditional function to go off a set amount of times per second to calculate things like gravity on an object.

This framework has worked very well for me when creating games. It works for any type of game, and works horribly for other types of programs. Sorry if my writin is unclear, I'm typing on my iPod and It would be hard for me to go back and edit things on here.

留蓝 2024-08-23 11:21:19

Eberly 的 3D 游戏引擎架构3D 游戏引擎设计 非常注重理论,但很好地涵盖了所有基础知识。

Eberly's 3D Game Engine Architecture and 3D Game Engine Design are rather heavy on the theory, but cover all of the bases quite well.

我的黑色迷你裙 2024-08-23 11:21:19

http:// Fivedots.coe.psu.ac.th/~ad/jg/

这家伙提出了一个很好的 oop 风格,并通过这本书帮助你构建一个引擎框架。它是好东西的现货。

http://fivedots.coe.psu.ac.th/~ad/jg/

This guy lays out a good oop style and through the book helps you build an engine frame. It's spot on good stuff.

妄断弥空 2024-08-23 11:21:19

如果您想编写一个简单的 2D 游戏,了解您实际想要做什么的一个好方法是:

  • 编写一个简单的游戏循环,它只是以您想要的分辨率显示帧缓冲区< /p>

  • 渲染一个给定方向的简单精灵,并且从屏幕边缘弹起的速度

  • 确保您的逻辑和显示代码分离

如果这听起来需要大量工作,或者如果它包含您的想法/术语我不能 100% 确定它们的意思:看一下现有的一两个游戏引擎。

如果您只是想了解它是如何完成的,编码是一种很好的学习方式。

如果您对开发游戏更感兴趣,我强烈推荐像 Unity 这样的东西作为基础,这样您就可以实际开发游戏。由于它是一个引擎,随着时间的推移,您将了解有多少个不同的部件以及它们如何互连。

If you want to code a simple 2d game, a good way to get an idea of what you#re actually trying to do is to:

  • write a simple game loop, that simply displays a frame buffer in the resolution you want

  • render a simple sprite with a a given direction and velocity bouncing off the screen edges

  • ensuring that your logic and display code are decoupled

If this sounds like a a lot of work, or if it contains ideas/ terms you're not 100% sure what they mean: Take a look at one or two of the existing game engines.

If you just want to get an idea of how it's done, coding something is a great way to learn.

If you're more interested in developing a game, I strongly recommend something like Unity as a base, so you can actually work on the game. And since it is an engine, you'll learn over time how many different parts there are, and how they interconnect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文