Back to "Introduction to Godot 4" Course

Part 2: Creating Your First 2D Scene

Valentino Phiri
Instructor Valentino Phiri
Published
Duration 2 min read
Series Status in progress

Welcome back! In Part 1, we installed Godot 4. Now, let’s dive into creating our first scene.

Advertisement Placeholder

This is where your high-revenue AdSense units will appear.

Understanding Nodes and Scenes

Godot uses a unique architecture:

  • A Node is the smallest building block. It can be a sprite, a sound, or a physics body.
  • A Scene is a collection of Nodes organized in a tree.

Creating the Main Scene

  1. In the top-left Scene dock, click 2D Scene. This creates a generic Node2D as the root.
  2. Rename this node to World.
  3. Save the scene by pressing Ctrl + S. Name it world.tscn.

Adding a Sprite

Every game needs visuals!

  1. Right-click the World node and select Add Child Node.
  2. Search for Sprite2D and add it.
  3. In the Inspector on the right, look for the Texture property. Drag the default icon.svg from the FileSystem dock into the Texture slot.

Congratulations! You have just created a scene and added a visual element to your game.

Writing the Movement Script

Let’s write a small script to make it move. We’ll start breaking down the logic starting from line 12:

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
extends Sprite2D

var speed = 400
var angular_speed = PI

func _process(delta):
    var direction = 0
    if Input.is_action_pressed("ui_left"):
        direction = -1
    if Input.is_action_pressed("ui_right"):
        direction = 1

    rotation += angular_speed * direction * delta
    var velocity = Vector2.UP.rotated(rotation) * speed
    position += velocity * delta

Next time, we’ll dive deeper into more advanced GDScript logic.

Advertisement Placeholder

This is where your high-revenue AdSense units will appear.

Share this article:
Sponsored

Special Developer Offer: 20% off at TechGadgets

Upgrade your workspace with premium hardware and software tools today.