godot游戏引擎自学入门笔记-- 实例化,官方文档翻译(三)

版权声明:本文为博主dark_tone暗色调 原创文章,未经博主允许不得转载。 https://blog.csdn.net/dark_tone/article/details/89039156

Creating a single scene and adding nodes into it might work for small projects, but as a project grows in size and complexity, the number of nodes can quickly become unmanageable. To address this, Godot allows a project to be separated into any number of scenes. This provides you with a powerful tool that helps you organize the different components of your game.

创建单个场景并添加节点可以用于小项目,但是随着一个项目的规模和复杂性的增长,节点的数量很快变得不可管理。
为了解决这个问题,godot允许一个项目被分成任意数量的场景。
这为你提供了一个强大的工具,帮助你组织游戏中的不同事物

In Scenes and nodes you learned that a scene is a collection of nodes organized in a tree structure, with a single node as the tree root.

在场景和节点章节,你学到了场景是以树结构组织的节点集合,仅有一个根节点。

You can create as many scenes as you like and save them to disk. Scenes saved in this manner are called “Packed Scenes” and have a .tscn filename extension.

您可以创建尽可能多的场景,并将它们保存到磁盘,以这种方式保存的场景称为“填充场景”,并有a.tscn文件名扩展
在这里插入图片描述

Once a scene has been saved, it can be instanced into another scene as if it were any other node.

一旦场景被保存,它可以被实例化到另一个场景中,就像它是其他节点一样
在这里插入图片描述

实例化举例

To learn how instancing works, let’s start by downloading a sample project

学习实例化如何工作,下载一个简单项目:
在这里插入图片描述
解压缩出来有两个项目,导入
在这里插入图片描述

This project contains two scenes: “Ball.tscn” and “Main.tscn”

工程包含两个场景Ball.tscn” 和 “Main.tscn

Open the Main scene, and then select the root node
We want to add an instance of the Ball scene as a child of Main. Click the “link”-shaped button (its hover-text says “Instance a scene file as a Node.”) and select the Ball.tscn file.

打开main场景,选择根节点,我们想把ball场景作为 main的子节点添加进去,选择link按钮
在这里插入图片描述
在这里插入图片描述

The ball will be placed at the top-left corner of the screen area (this is (0, 0) in screen coordinates). Click and drag the ball somewhere near the top-center of the scene
Press “Play” and watch the ball fall to the bottom of the screen

球将被放置在屏幕区域的左上角(这是屏幕坐标的0.0点)
点击和拖动球在场景顶部中心附近的任何地方
按下“播放”,观察球落在屏幕的底部
在这里插入图片描述

You can add as many instances as you like to a scene, either by using the “Instance” button again, or by clicking on the ball instance and pressing “Duplicate” (Ctrl-D):

您可以添加一个场景所需的尽可能多的实例,通过再次使用“实例”按钮,或者单击球实例并按下“复制”(Ctrl-D)
在这里插入图片描述

Instancing can be useful when you want to create many copies of the same object. It is also possible to create instances in code by using GDScript

当您想要创建同一对象的许多副本时,实例化是有用的,也可以使用GDScript在代码中创建实例。

猜你喜欢

转载自blog.csdn.net/dark_tone/article/details/89039156