Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

노드와 씬

:ref:`doc_key_concepts_overview`에서 우리는 Godot 게임이 씬의 트리이며 각 씬은 노드의 트리라는 것을 알아보았습니다. 이 레슨에서는 이들에 대해 좀 더 자세히 설명합니다. 또한 첫 번째 씬을 생성할 것입니다.

노드

노드(Node)는 게임의 기본 구성 요소입니다. 이들은 요리 레시피의 재료와 같습니다. 이미지를 표시하거나 사운드를 재생하거나 카메라를 표현하는 등 수십 가지 종류가 있습니다.

../../_images/nodes_and_scenes_nodes.webp

All nodes have the following characteristics:

  • 이름.

  • 수정할 수 있는 속성.

  • 매 프레임마다 업데이트를 위한 콜백을 받습니다.

  • 새 속성과 기능으로 그것들을 확장시킬 수 있습니다.

  • 다른 노드의 자식으로 그것들을 추가할 수 있습니다.

The last characteristic is important. Together, nodes form a tree, which is a powerful feature to organize projects. Since different nodes have different functions, combining them produces more complex behavior. As we saw before, you can build a playable character the camera follows using a CharacterBody2D node, a Sprite2D node, a Camera2D node, and a CollisionShape2D node.

../../_images/nodes_and_scenes_character_nodes.webp

노드를 캐릭터와 같이 트리로 구성할 때, 이 구조를 "씬(Scene)"이라고 부릅니다. 씬을 저장한 후에는, 에디터에서 새로운 노드 유형처럼 작동하여 기존 노드의 자식으로 추가할 수 있습니다. 이 경우 씬의 인스턴스는 내부를 숨긴 단일 노드로 표시됩니다.

씬을 사용하면 게임의 코드를 원하는 대로 구성할 수 있습니다. **노드를 조합**하여 게임 캐릭터의 달리기와 점프, 체력 바, 상호작용할 수 있는 상자 등과 같이 사용자 정의 및 복잡한 노드 유형을 만들 수 있습니다.

../../_images/nodes_and_scenes_3d_scene_example.png

기본적으로 Godot 에디터는 씬 에디터입니다. UI로 되어있는 2D와 3D 씬을 수정하는 툴은 많이 있지만, Godot 프로젝트는 당신이 필요로 하는 그 많은 씬을 포함합니다. 게임 엔진은 그저 메인 씬 만을 필요로 하며, 게임을 만들거나 플레이할 때 Godot이 제일 먼저 불러옵니다.

On top of acting like nodes, scenes have the following characteristics:

  1. 씬은 항상 하나의 루트 노드를 가지며, 위의 예시에서는 "Character"가 해당합니다.

  2. You can save them to your local drive and load them later.

  3. 씬의 인스턴스를 원하는 만큼 생성할 수 있습니다. 예를 들어, "Character" 씬에서 게임 내에 다섯 개 또는 열 개의 캐릭터를 생성할 수 있습니다.

첫 번째 씬 만들기

Let's create our first scene with a single node. To do so, you will need to create a new project first. After opening the project, you should see an empty editor.

../../_images/nodes_and_scenes_01_empty_editor.webp

In an empty scene, the Scene dock on the left shows several options to add a root node quickly. "2D Scene" adds a Node2D node, "3D Scene" adds a Node3D node, and "User Interface" adds a Control node. These presets are here for convenience; they are not mandatory. "Other Node" lets you select any node to be the root node. In an empty scene, "Other Node" is equivalent to pressing the "Add Child Node" button at the top-left of the Scene dock, which usually adds a new node as a child of the currently selected node.

We're going to add a single Label node to our scene. Its function is to draw text on the screen.

"자식 노드 추가(Add Child Node)" 버튼 또는 "다른 노드(Other Node)"를 눌러 루트 노드를 생성합니다.

../../_images/nodes_and_scenes_02_scene_dock.webp

대화 상자 제작 노드는 가능한 노드의 나열을 보여줍니다.

../../_images/nodes_and_scenes_03_create_node_window.webp

Label 노드를 선택합니다. 목록을 필터링하기 위해 이름을 입력할 수 있습니다.

../../_images/nodes_and_scenes_04_create_label_window.webp

그것을 선택하기 위해서 라벨 노드를 클릭하고 창 하단의 만들기 버튼을 누릅니다.

../../_images/nodes_and_scenes_05_editor_with_label.webp

씬의 첫 번째 노드를 추가하면 많은 일이 발생합니다. Label은 2D 노드 유형이므로 씬이 2D 작업 영역으로 변경됩니다. Label이 선택된 채로 뷰포트의 좌상단에 나타납니다. 노드는 왼쪽의 씬(Scene) 독에 나타나며, 노드의 속성은 오른쪽의 인스펙터(Inspector) 독에 나타납니다.

노드 속성 변경

다음 단계는 라벨의 "Text"를 바꿉니다. "Hello, World"로 바꿔보세요.

뷰포트의 오른쪽에 있는 인스펙터 독으로 이동하세요. Text 속성 아래의 필드를 클릭하고 "Hello World"라고 입력하세요.

../../_images/nodes_and_scenes_06_label_text.webp

입력하는 동안 뷰포트에 텍스트가 그려지는 것을 볼 수 있을 것입니다.

더 보기

You can edit any property listed in the Inspector as we did with the Text. For a complete reference of the Inspector dock, see The Inspector.

툴바에서 이동 도구(move tool)를 선택하여 Label 노드를 뷰포트에서 이동할 수 있습니다.

../../_images/nodes_and_scenes_07_move_tool.webp

Label을 선택한 상태에서 뷰포트에서 어느 곳이든 클릭한 채로 드래그하여 사각형으로 지정된 뷰의 중앙으로 이동시킵니다.

../../_images/nodes_and_scenes_08_hello_world_text.webp

씬 실행

씬을 실행할 준비가 되었습니다! 화면 오른쪽 상단의 씬 재생 버튼을 누르거나 F6`(macOS의 경우 :kbd:`Cmd + R)을 누릅니다.

../../_images/nodes_and_scenes_09_play_scene_button.webp

A popup invites you to save the scene, which is required to run it. Click the Save button in the file browser to save it as label.tscn.

../../_images/nodes_and_scenes_10_save_scene_as.webp

참고

씬을 저장하는 것은 에디터의 다른 파일 대화 상자와 마찬가지로, 프로젝트 내에서만 파일을 저장할 수 있습니다. 창 상단의 res:// 경로는 프로젝트의 루트 디렉토리를 나타내며 "리소스 경로"를 의미합니다. Godot에서 파일 경로에 대한 자세한 내용은 :ref:`doc_filesystem`을 참조하십시오.

새 창에서 애플리케이션이 열리고 "Hello World"라는 텍스트가 표시되어야 합니다.

../../_images/nodes_and_scenes_11_final_result.webp

Close the window or press F8 (Cmd + . on macOS) to quit the running scene.

Setting the main scene

테스트 씬을 실행하기 위해 씬 실행(Play Scene) 버튼을 사용합니다. 옆에 있는 다른 버튼을 사용하면 프로젝트의 메인 씬을 설정하고 실행할 수 있습니다. 이를 위해 F5 (mac OS는 Cmd + B)를 누를 수 있습니다.

../../_images/nodes_and_scenes_12_play_button.webp

팝업 창이 나타나고 메인 씬을 선택하라는 메시지가 표시됩니다.

../../_images/nodes_and_scenes_13_main_scene_popup.webp

Click the Select button, and in the file dialog that appears, double click on label.tscn.

../../_images/nodes_and_scenes_14_select_main_scene.webp

데모가 다시 실행되어야 합니다. 앞으로 프로젝트를 실행할 때마다 Godot은 이 씬을 시작점으로 사용할 것입니다.

참고

The editor saves the main scene's path in a project.godot file in your project's directory. While you can edit this text file directly to change project settings, you can also use the "Project -> Project Settings" window to do so. For more information, see 프로젝트 설정.

다음 파트에서는 게임 및 Godot에서 또 다른 중요한 개념인 씬의 인스턴스(instances)를 생성하는 것에 대해 논의하겠습니다.