In this video, we’ll code a spaceship that moves by itself.
Under each video, you’ll find explanations for new concepts and answers to your questions.
In games, a sprite is an image that can move. We use the term to talk about almost all drawings in a game: characters, monsters, doors, chests, weapons, clouds, and so on. The word “sprite” is prevalent in 2D games.
You’ll also hear game artists call about any image they create a “sprite.”
extends
keywordThe extends
keyword tells the computer that your script
directly extends code from the game engine.
For example, the line extends Sprite
tells Godot to
append your code to all the code the Godot developers wrote for the
type. That’s how you can access the
_process()
function or member variables like
position
and rotation
from GDScript.
In Godot, every script must extend a type from the game engine. The
is one of many node types built into the engine, as we saw with the Add Node dialog.You will learn how to create new types and extend them later in the course.
A velocity is a vector that combines a direction and a speed into a single value. The vector’s orientation gives us its direction, and its length represents the speed.
For more information on scenes, nodes, and scripts, please check out the dedicated guide in this chapter.
We often use names with capital letters and no spaces in code to represent most types. It’s a convention, and we call that “PascalCase.”
In this project, we use the same convention for related files. For example, we write the names of files, scripts, and folders in PascalCase.
We do this because PascalCase is a standard convention in the Godot community. Godot names nodes, scenes, and script files in PascalCase by default, so people tend to use it.
You can write file names however you prefer. We recommend picking a convention for each project and sticking to it. It helps keep things easy to search and organized for you and your teammates.
The next video will run you through the first practice step-by-step.
Here’s the complete code listing for the ship after this lesson.
extends Sprite
var velocity := Vector2(500, 0)
func _process(delta: float) -> void:
+= velocity * delta
position = velocity.angle() rotation