Nodi e Scene¶
Su Overview of Godot's key concepts, abbiamo visto che un gioco su Godot è un albero di scene e che ogni scena è un albero di nodi. In questa lezione, approfondiamo su di loro. Inoltre creerete la vostra prima scena.
Nodi¶
I nodi sono i blocchi fondamentali del tuo gioco. Sono come ingredienti in una ricetta. Ci sono dozzine di tipi che possono mostrare un’immagine, riprodurre un suono, rappresentare una camera, e molto altro.

Tutti i nodi hanno i seguenti attributi:
Un nome.
Proprietà modificabili.
They receive callbacks to update every frame.
You can extend them with new properties and functions.
You can add them to another node as a child.
L’ultimo attributo è chiave. Insieme, i nodi formano un albero, che è una potente funzionalità per organizzare progetti. Siccome diversi nodi hanno diversi funzioni, combinarli produce comportamenti complessi. Come abbiamo visto prima, puoi costruire un personaggio giocabile seguito dalla camera usando un nodo cinematico chiamato “Personaggio”, un nodo sprite, un nodo camera, e un nodo forma di collisione.

Scene¶
Quando organizzi nodi in un albero, come il nostro personaggio, possiamo chiamare questa formazione una scena. Una volta salvata, la scena si presenta come un nuovo nodo nell’editor, dove possiamo aggiungerlo come figlio di un nodo esistente. In questo caso, l’istanza della scena appare come nodo singolo con interni nascosti.
Le scene di consentono di strutturare il codice del gioco in qualunque modo tu voglia. Puoi comporre nodi per creare nodi personalizzati e complessi, come un personaggio di gioco che si muove e salta, una barra della vita, una cesta con cui puoi interagire, e molto altro.

The Godot editor essentially is a scene editor. It has plenty of tools for editing 2D and 3D scenes, as well as user interfaces. A Godot project can contain as many of these scenes as you need. The engine only requires one as your application's main scene. This is the scene Godot will first load when you or a player runs the game.
On top of acting like nodes, scenes have the following attributes:
Essi hanno sempre un nodo radice, come il "Personaggio" nel nostro esempio.
Puoi salvarli sul tuo disco fisso e caricarli in seguito.
You can create as many instances of a scene as you'd like. You could have five or ten characters in your game, created from your Character scene.
Creating your first scene¶
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.

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 Spatial 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.
Press the "Add Child Node" button or "Other Node" to create a root node.

The Create Node dialog opens, showing the long list of available nodes.

Seleziona il nodo Label. Puoi scrivere il suo nome per filtrarlo sulla lista.

Clicca sul nodo Label per selezionarlo e clicca il pulsante Crea nella parte inferiore della finestra.

Molto accade quando aggiungi il primo nodo di una scena. La scena cambia dal piano di lavoro 2D perchè Label è un nodo di tipo 2D. Il Label appare, selezionato, nel bordo in alto a sinistra del Viewport. Il nodo appare nel riquadro Scene sulla sinistra, e le proprietà del nodo appaiono nel pannello Inspector sulla destra.
Changing a node's properties¶
The next step is to change the Label's "Text" property. Let's change it to "Hello World".
Muoviti sul riquadro Inspector sulla destra del Viewport. Clicca dentro il campo sotto la proprietà Testo e scrivi "Hello World".

You will see the text draw in the viewport as you type.
Puoi muovere il tuo nodo Label nel Viewport selezionando lo strumento muovi nella barra degli strumenti.

Con la Label selezionata, premi e trascina ovunque nel Viewport per muoverlo al centro della vista delimitata dal rettangolo.

Running the scene¶
Everything's ready to run the scene! Press the Play Scene button in the top-right of the screen or press F6 (Cmd + R on macOS).

Un popup ti invita a salvare la scena, che è richiesta per avviarlo.

Premi il tasto Sì, e nel navigatore file che appare, seleziona il tasto Salva per salvarlo come "Label.tscn".

Nota
The Save Scene As dialog, like other file dialogs in the editor, only
allows you to save files inside the project. The res://
path at
the top of the window represents the project's root directory and
stands for "resource path". For more information about file paths in
Godot, see File system.
The application should open in a new window and display the text "Hello World".

Close the window or press F8 to quit the running scene.
Nota
If this doesn't immediately work and you have a hiDPI display on at least one of your monitors, go to Project -> Project Settings -> Display -> Window then enable Allow Hidpi under Dpi.
Setting the main scene¶
To run our test scene, we used the Play Scene button. Another button next to it allows you to set and run the project's main scene. You can press F5 (Cmd + B on macOS) to do so.

A popup window appears and invites you to select the main scene.

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

The demo should run again. Moving forward, every time you run the project, Godot will use this scene as a starting point.
Nota
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.
In the next part, we will discuss another key concept in games and in Godot: creating instances of a scene.