Creating scenes
First thing first. Create my project.
Holy Carp! Baaam. An absolutely legendary name for my soon-to-be amazing game.
Now we've got our very first scene, let's call it main_scene. This is the mothership. The place where I'll instantiate all the other scenes.
Oh, and by the way. Godot works with scenes instead of traditional objects.
Main Scene
I changed the window size of my game by going to Project -> Project Settings -> Display (Window) and setting the viewport width and height to 720×1280. It's a vertical game, after all.
But since I'm developing on my laptop, that resolution doesn't exactly fit on my screen. The viewport would stretch beyond my screen height, which is… not ideal.
So I did what any reasonable developer does, I googled it.
Turns out, in Godot you can use Window Width Override and Window Height Override. Basically, you keep your actual game resolution at 720×1280, but tell the editor to display it smaller while you're working.
So for now, I set the override to 360×640. Same aspect ratio. Half the size. Much less pain.
That's pretty much everything I did for the main scene.
Wait. Not everything.
I also added a Camera and positioned it over the viewport. Do I actually need it? Not entirely sure. So I had to google this as well.
In Godot, a Camera2D controls what part of the world you see. If your game is static and nothing moves outside the screen, you technically don't need one. But the second you want scrolling, following a player, zooming, or any kind of movement? You'll want that camera there.
So I'm going to keep it for the future, or just pretending I know what I’m doing.
Node Structure & Project Structure
For this part, I actually did a little homework on what's considered "best practice", basically, how to set things up now so I don't hate myself later.
I really want to keep my project tidy, and a few people suggested breaking scripts into smaller Nodes as children of the root node. At first, I had no clue what that even meant, but after some Googling, it clicked. I'll dive deeper into this when I cover my Player scene.
When it comes to my project structure, its very straight forward, at least for a small project like this:
Setting up the Player
Now it's time for the Player scene.
I started with a CharacterBody2D(CB2) node, because I don't need physics for this game. If I did, I'd probably go with a Rigidbody2D… I think. For now, CB2 is plenty. I didn't mess with any of its settings at the start, mostly because they might as well have been written in alien for all I understood.
Next, I added a CollisionShape2D as a child of the Player node(CB2). This is crucial, without it, I can't "catch" the falling fish or get pummeled by the bad stuff.
Finally, I added a Sprite2D node and the default icon.svg as its sprite, just so something actually shows up while I'm working.
This is coming along nicely.
But now we actually need to move the Player. And this is where key inputs and scripts does its thing.
Basic Movement
I went to Project -> Project Settings -> Input Map at the top, and added a few actions:
- left - triggered by the A key and the left arrow
- right - same as left but opposite keys
- helper - triggered by the Space key
Now that the key mapping is done, I should be able to move this bad boy around the viewport, right?
Nope. Not that easy. We still have to tell this mess what to do. Scripts, people. Scripts.
Enter GDScript and the appointed scripts.
Like I mentioned earlier, we need to break our scripts up. I don't want one giant 10,000+ line monstrosity, that's a nightmare to manage.
So, I made a simple node called MovementScriptNode and made it a child of the Player node. On this node, I attached a script to handle movement.
But there's a catch, this script doesn't automatically know that it's supposed to move the Player, because right now it's just a lonely node floating in space.
We need to tell the Player node to use the info in the script attached to MovementScriptNode. We do this by:
extends CharacterBody2D
@onready var movement = $MovementScriptNode
func _physics_process(delta: float) -> void:
movement.move_player(self, delta)
So what this code means is, in very short terms: "Whattup MovementScriptNode, please move me." the move_player is a function in MovementScriptNode. As you can see below:
extends Node
@export var speed = 400
func move_player(character, _delta):
var input_direction = Input.get_axis("left", "right")
character.velocity.x = input_direction * speed
if character.velocity.x > 0:
character.get_node("Sprite2D").flip_h = true
elif character.velocity.x < 0:
character.get_node("Sprite2D").flip_h = false
character.move_and_slide()
I could go line by line here, if you want, let me know in the comments.
Basically, the movement script does this: reads input, sets the Player's velocity, flips the sprite, and then tells the Player to actually move. It uses a parameter called character, which in the Player script is passed as self.
Now the Player moves like it should… except it can wander off the viewport. I'll fix that later, once I figure out how. (ignore the size of the Player node.)
My dear readers. Remember that everything I write is not always 100% correct. I do mistakes and I'm a novice at this. So if you find a mistake or just have some random feedback on anything. Please comment!




Top comments (0)