SSantoshi/GamesSearch

Getting started

Make your first 2D game in Godot, step by step

Build a complete little game in Godot 4 in one sitting: move a character, collect coins against the clock, show a score, restart, and export it to play in a browser.

In this guide you build Coin Rush: move a character around the screen and grab as many coins as you can in 30 seconds. It's small on purpose. By the end you'll have used the ideas every Godot game is made of: scenes, nodes, scripts, input, collisions, signals and a game loop, and you'll have a version you can share as a link.

New to engines? Read Godot vs Unity vs Unreal first, then come back.

1. Install Godot and create the project

  1. Download Godot 4 (the standard version, not the .NET one) from godotengine.org. There's nothing to install: unzip it and run it.
  2. Click Create, name the project coin-rush, and pick the Compatibility renderer. It runs on older computers and is the renderer Godot uses for web exports.

Godot projects are built from scenes, and scenes are trees of nodes. A node is one thing with one job: a sprite draws an image, a collision shape defines a hitbox, a timer counts down. You'll make three scenes: a player, a coin and the main level.

2. The player

  1. Create a new scene. Choose Other Node and add a CharacterBody2D. Rename it Player.
  2. Add a Sprite2D child and drag icon.svg from the FileSystem panel into its Texture. This placeholder is fine for now.
  3. Add a CollisionShape2D child, set its Shape to a new RectangleShape2D, and resize it to cover the sprite.
  4. In the Node panel, open Groups and add the player to a group called player. The coin will use this to recognise it.
  5. Save the scene as player.tscn, then attach a script to Player (player.gd):
extends CharacterBody2D

const SPEED := 300.0

func _physics_process(_delta: float) -> void:
	# Arrow keys are mapped to the built-in ui_* actions.
	var direction := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
	velocity = direction * SPEED
	move_and_slide()
	# Keep the player on screen.
	position = position.clamp(Vector2.ZERO, get_viewport_rect().size)

Input.get_vector turns four directions into one vector, so diagonal movement isn't faster than straight movement. move_and_slide moves the body and handles collisions for you, and Godot already scales it by the frame time. (Our game loop guide explains why that matters.)

3. The coin

  1. Create a new scene with an Area2D root called Coin. Areas detect overlaps without blocking movement, which is exactly what a pickup needs.
  2. Add a Sprite2D with icon.svg and set its Scale to 0.4 so it looks different from the player. Add a CollisionShape2D with a CircleShape2D.
  3. Save it as coin.tscn and attach coin.gd:
extends Area2D

signal collected

func _on_body_entered(body: Node2D) -> void:
	if body.is_in_group("player"):
		collected.emit()
		queue_free()
  1. Select Coin, open the Node panel, double-click the body_entered signal and connect it to _on_body_entered in the coin script.

A signal is a message: the coin announces "I was collected" without needing to know who keeps score. That keeps scenes independent and easy to reuse.

4. The main scene and the rules

  1. Create a scene with a Node2D root called Main. Drag player.tscn into it and move the player to the middle of the screen.
  2. Add a Label child, place it in the top-left corner, and give it a large font size in Theme Overrides.
  3. Save it as main.tscn, set it as the main scene (Project → Project Settings → Application → Run → Main Scene), and attach main.gd:
extends Node2D

const COIN_SCENE := preload("res://coin.tscn")
const ROUND_SECONDS := 30.0

var score := 0
var time_left := ROUND_SECONDS
var game_over := false

@onready var player: CharacterBody2D = $Player
@onready var label: Label = $Label

func _ready() -> void:
	for i in 8:
		spawn_coin()

func spawn_coin() -> void:
	var coin := COIN_SCENE.instantiate()
	var size := get_viewport_rect().size
	coin.position = Vector2(randf_range(40, size.x - 40), randf_range(80, size.y - 40))
	coin.collected.connect(_on_coin_collected)
	add_child(coin)

func _on_coin_collected() -> void:
	score += 1
	spawn_coin()

func _process(delta: float) -> void:
	if game_over:
		if Input.is_action_just_pressed("ui_accept"):
			get_tree().reload_current_scene()
		return
	time_left = max(time_left - delta, 0.0)
	label.text = "Coins: %d    Time: %d" % [score, int(ceil(time_left))]
	if time_left == 0.0:
		game_over = true
		player.set_physics_process(false)
		label.text = "Time's up! You got %d coins. Press Enter to play again." % score

Press F5 to play. Every coin you grab spawns a new one somewhere random, the timer counts down, and when it hits zero the player freezes until you press Enter.

5. Make it feel like a game

Small touches make a big difference. Try one at a time:

6. Share it as a link

  1. Open Editor → Manage Export Templates and download the templates for your Godot version.
  2. Open Project → Export, add a Web preset, and export to an empty folder as index.html.
  3. Zip the contents of that folder (not the folder itself) and upload it to itch.io as an HTML game. Our guide to publishing on itch.io walks you through it.

The default web export is single-threaded, which runs on itch.io without extra server settings. One limit to know: Godot 4 projects written in C# can't export to the web yet, which is one more reason to start with GDScript.

What we learned shipping our first Godot games

Merge 2048 was our first Godot game and Tank Arcade one of the next. Three things from them apply directly to Coin Rush.

When you add sound, define the audio buses in the project, not in code. It's tempting to create "Music" and "SFX" buses from a script at startup. On desktop that works. In the web export, Godot wired our master bus back into those buses, making a loop that the browser silenced completely: no errors, just no sound. Create the buses in the Audio panel at the bottom of the editor instead, which saves them in default_bus_layout.tres. We hit this twice, in two different games, before it stuck.

You might not need sprite files at all. Tank Arcade has no image assets. The tanks, walls, crates, scorch marks and tread tracks are all drawn in code with Godot's _draw() functions, plus a glow layer for anything bright. For a game made of simple shapes, that's faster than finding art that matches, and the download stays tiny. Try replacing the coin's icon.svg with a _draw() that calls draw_circle() and see how far it takes you.

A best score needs somewhere to live. The "best score" idea in step 5 saves to a file. In a web build, that file lives in the browser's storage, and some places that host games, including the sandboxed play frame on our own arcade pages, don't allow any storage. Our games check with OS.is_userfs_persistent() before they save, and offer a separate full-screen page where saving works. Expect your save code to fail sometimes, and make sure the game still runs when it does.

What you just learned

You used scenes and nodes, a script per scene, the input system, physics bodies and areas, a signal, a timer driven by delta, and an export. Every bigger Godot game is these same pieces arranged in more ways. Ready for a third axis? Make your first 3D game in Godot uses the same pieces to build a small platformer. Or write a one-page design document for your own idea, and keep the scope small enough to finish.


Sources & credits

This guide is original writing by Santoshi Games. It draws on, and links to, the free resources below. All rights to them belong to their creators. Please support them.

Questions people ask

I want to make my first 2D game. Is Godot a good place to start?
Yes. Godot is free, downloads in a minute, runs on modest laptops, and its 2D tools are built for 2D rather than being 3D tools turned sideways. GDScript reads a lot like Python, which helps if you've never coded, and a finished game exports to the web as a link anyone can play. This guide builds Coin Rush, a 30-second coin-collecting game, from an empty project to a shareable web build.
Which Godot tutorial will not overwhelm me if I have never coded?
Pick one that finishes a tiny game in an evening and explains every line instead of piling on features. This guide does that: one player, one coin, a score and a timer, in a few short scripts. Godot's official "Your first 2D game" tutorial, Dodge the Creeps, is a good next step. Leave the dream RPG for later.
How do I make a character run and jump in 2D in Godot?
Use a CharacterBody2D. In _physics_process, add gravity to velocity.y while the character isn't on the floor, set velocity.x from left and right input times a speed, set velocity.y to a negative jump value when jump is pressed and is_on_floor() is true, then call move_and_slide(). This guide uses the same node for top-down movement, and Godot's built-in CharacterBody2D script template gives you the platformer version ready to edit.
What is the easiest way to build levels for a 2D game?
Godot's TileMapLayer node. Import a tileset image, mark which tiles have collision, then paint levels like you would in a drawing program. It's quick to edit and light on memory, so you can redesign a level in minutes. Start with a free CC0 tileset such as one of Kenney's, block out a single screen, play it and adjust, rather than drawing a huge map up front.
Do I need to be an artist to make a decent-looking 2D game?
No. Plenty of good-looking indie games use simple shapes, a small colour palette and consistent sizes. You can also use free CC0 art, such as Kenney's packs, and swap in your own later. This guide uses Godot's icon as a placeholder on purpose: make the game fun first, then make it pretty. Our free game assets guide explains which licences are safe to use.
← Back to learn