当前位置: 首页 > 工具软件 > godot-go > 使用案例 >

godot游戏引擎自学入门笔记--GDScript与c++,官方文档翻译(五)

屠瑞
2023-12-01

Before Godot 3.0, the only choice for scripting a game was to use GDScript. Nowadays, Godot has four (yes, four!) official languages and the ability to add extra scripting languages dynamically!

在godot 3.0 之前,编写游戏的唯一选择是使用GDScript,现在,godot有四个(是的,四个!)官方语言以及动态添加额外脚本语言的能力。

This is great, mostly due to the large amount of flexibility provided, but it also makes our work supporting languages more difficult.

这很好,主要是因为提供了大量的灵活性,但它也使得我们支持语言的工作变得更加困难。

The “main” languages in Godot, though, are GDScript and VisualScript. The main reason to choose them is their level of integration with Godot, as this makes the experience smoother; both have slick editor integration, while C# and C++ need to be edited in a separate IDE. If you are a big fan of statically typed languages, go with C# and C++ instead.

虽然godot的主要语言是 GDScript 和 VisualScript,选择它们的主要原因是它们与godot的整合程度,让表达更流畅,两者都有平滑的编辑器集成。而C#和C++需要在单独的IDE中进行编辑,如果您是静态类型语言的粉丝,请使用C#语言和C++替代。

GDScript

GDScript is, as mentioned above, the main language used in Godot. Using it has some positive points compared to other languages due to its high integration with Godot:

如上所述,GDScript是godot使用的主要语言。与其他语言相比,它在godot中高度集成。

it’s simple, elegant, and designed to be familiar for users of other languages such as Lua, Python, Squirrel, etc.
Loads and compiles blazingly fast.
The editor integration is a pleasure to work with, with code completion for nodes, signals, and many other items pertaining to the scene being edited.
Has vector types built-in (such as Vectors, transforms, etc.), making it efficient for heavy use of linear algebra.
Supports multiple threads as efficiently as statically typed languages - one of the limitations that made us avoid VMs such as Lua, Squirrel, etc.
Uses no garbage collector, so it trades a small bit of automation (most objects are reference counted anyway), by determinism.
Its dynamic nature makes it easy to optimize sections of code in C++ (via GDNative) if more performance is required, all without recompiling the engine.

①它简单、典雅,类似于其他语言lua,python等
②快速加载和编译
③随着节点的代码完成,与编辑场景有关的许多其他项目代码完成,编辑器集成是一个愉快的工作
④内置向量类型(如向量、变换等),使其有效地用于线性代数的大量使用。
⑤支持多线程与静态类型语言一样有效,这是我们避免使用诸如Lua、Squirrel等虚拟机的原因之一。
⑥不使用垃圾收集器,所以它确定性地自动处理这部分(大多数对象都是引用计数)
⑦它的动态特性使得c++代码段的优化变得容易(通过 GDNative),如果需要更多的性能,都不需要重新编译引擎

c++

Finally, one of our brightest additions for the 3.0 release: GDNative allows scripting in C++ without needing to recompile (or even restart) Godot.
Any C++ version can be used, and mixing compiler brands and versions for the generated shared libraries works perfectly, thanks to our use of an internal C API Bridge.

最后,我们在3.0发布版最聪明的补充之一:GDNative允许在C++中编写脚本,而不需要重新编译(甚至重启)godot。
任何C++版本都可以使用,由于我们使用了内部的C API作为桥梁,混合编译器和生成的共享库都可以完美工作。

This language is the best choice for performance and does not need to be used throughout an entire game, as other parts can be written in GDScript or Visual Script. However the API is clear and easy to use as it resembles, mostly, Godot’s actual C++ API
More languages can be made available through the GDNative interface, but keep in mind we don’t have official support for them

这种语言是性能最好的选择,不需要在整个游戏中使用。因为其他部分可以用GDScript或VisualScript编写。不管怎样,它的API清晰且易于使用,类似于Godot的C++ API

通过GDNative接口可以使用更多语言,但请记住我们没有官方支持

然后我去找了下官方文档关于GDNative部分,发现它非常繁杂,看得头晕老涨的,自己配置绝对会懵。
为了最大的适用性,还是使用GDScript吧。

脚本化场景

For the rest of this tutorial we’ll set up a GUI scene consisting of a button and a label, where pressing the button will update the label. This will demonstrate:
Writing a script and attaching it to a node.
Hooking up UI elements via signals.
Writing a script that can access other nodes in the scene.

本教程的其余部分,我们将设置一个按钮和标签组成的GUI场景,按下按钮将更新标签,这将说明
①编写脚本并将其附加到节点
②通过信号钩住UI元素
③编写可以访问场景中其他节点的脚本

Before continuing, please make sure to read the GDScript reference. It’s a language designed to be simple, and the reference is short, so it will not take more than a few minutes to get an overview of the concepts.

官方推荐先学一学GDScript

 类似资料: