Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Godot Engine Game Development Projects

You're reading from   Godot Engine Game Development Projects Build five cross-platform 2D and 3D games with Godot 3.0

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781788831505
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Chris Bradfield Chris Bradfield
Author Profile Icon Chris Bradfield
Chris Bradfield
Arrow right icon
View More author details
Toc

About nodes and scenes

Nodes are the basic building blocks for creating games in Godot. A node is an object that can represent a variety of specialized game functions. A given type of node might display graphics, play an animation, or represent a 3D model of an object. The node also contains a collection of properties, allowing you to customize its behavior. Which nodes you add to your project depends on what functionality you need. It's a modular system designed to give you flexibility in building your game objects.

In your project, the nodes you add are organized into a tree structure. In a tree, nodes are added as children of other nodes. A particular node can have any number of children, but only one parent node. When a group of nodes are collected into a tree, it is called a scene, and the tree is referred to as the scene tree:

Scenes in Godot are typically used to create and organize the various game objects in your project. You might have a player scene that contains all the nodes and scripts that make the player's character work. Then, you might create another scene that defines the game's map: the obstacles and items that the player must navigate through. You can then combine these various scenes into the final game using instancing, which you'll learn about later.

While nodes come with a variety of properties and functions, any node's behavior and capabilities can also be extended by attaching a script to the node. This allows you to write code that makes the node do more than it can in its default state. For example, you can add a Sprite node to your scene to display an image, but if you want that image to move or disappear when clicked, you'll need to add a script to create that behavior.

Scripting in Godot

At the time of writing, Godot provides three official languages for scripting nodes: GDScript, VisualScript, and C#. GDScript is the dedicated built-in language, providing the tightest integration with the engine, and is the most straightforward to use. VisualScript is still very new and in the testing stage, and should be avoided until you have a good understanding of Godot's workings. For most projects, C# is best reserved for those portions of the game where there is a specific performance need; most Godot projects will not need this level of additional performance. For those that do, Godot gives the flexibility to use a combination of GDScript and C# where you need them.

In addition to the three supported scripting languages, Godot itself is written in C++ and you can get even more performance and control by extending the engine's functionality directly. See Chapter 7, Additional Topics, for information on using other languages and extending the engine.

All of the games in this book use GDScript. For the majority of projects, GDScript is the best choice of language. It is very tightly integrated with Godot's Application Programming Interface (API), and is designed for rapid development.

About GDScript

GDScript's syntax is very closely modeled on the Python language. If you are familiar with Python already, you will find GDScript very familiar. If you are comfortable with another dynamic language, such as JavaScript, you should find it relatively easy to learn. Python is very often recommended as a good beginner language, and GDScript shares that user-friendliness.

This book assumes you have at least some programming experience already. If you've never coded before, you may find it a little more difficult. Learning a game engine is a large task on its own; learning to code at the same time means you've taken on a major challenge. If you find yourself struggling with the code in this book, you may find that working through an introductory Python lesson will help you grasp the basics.

Like Python, GDScript is a dynamically typed language, meaning you do not need to declare a variable's type when creating it, and it uses whitespace (indentation) to denote code blocks. Overall, the result of using GDScript for your game's logic is that you write less code, which means faster development and fewer mistakes to fix.

To give you an idea of what GDScript looks like, here is a small script that causes a sprite to move from left to right across the screen at a given speed:

extends Sprite

var speed = 200

func _ready():
position = Vector2(100, 100)

func _process(delta):
position.x += speed * delta
if position.x > 500:
position.x = 0

Don't worry if this doesn't make sense to you yet. In the following chapters, you'll be writing lots of code, which will be accompanied by explanations of how it all works.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime