Game Design & Development ยท Lesson 4
Build 2D Games Faster
A game engine takes care of the repetitive code so you can spend more time making your game fun. Meet two browser-based enginesโKaplay and Phaserโand decide which one fits your project.
Watch the engine do one frame of work
Predict: if a player has gravity but no solid collision response, will the floor stop it? Test below. Each click advances one slowed teaching frame (0.1 seconds).
- Read the selected input.
- Update velocity and position.
- Resolve solid collisions.
- Draw the new state.
You still write the rules: what happens when a coin is collected, how to win, and what makes the game fun.
This is a simplified teaching model, not a running Kaplay or Phaser game. Real engines manage timing and their own update/physics order.
Your route from idea to playable game
Use these lessons when you need the next skill. The tutorials teach game mechanics; adapt their rules to your chosen engine.
0The quick answer
For a first JavaScript prototype, Kaplay is a useful starting point. For a project built around tilemaps and scene organization, explore Phaser 3. Both can build substantial games; choose based on the features, examples, and code you understand.
1What does a game engine do?
Think of a game engine as a toolbox for making games. It gives you ready-made code for jobs that almost every game needs.
- Scenes โ switch between a menu, a level, and a game-over screen
- Sprites โ show and animate characters, enemies, and items
- Physics โ add gravity, speed, bouncing, and collisions
- Controls โ read the keyboard, mouse, touchscreen, or gamepad
- Sound โ play music and sound effects
- Loading โ prepare images and sounds before the game begins
- Camera โ follow the player, zoom, or shake after a big hit
2Meet Kaplay and Phaser
Both engines are free and work in a web browser. They can make the same kinds of 2D games, but they feel different to use.
Kaplay Beginner Friendly
- Short, readable code
- Add abilities like gravity as building blocks
- Great for platformers and small arcade games
- Fast setup for class projects and game jams
Phaser 3 Scene & Map Tools
- Uses an organized scene system
- Includes several physics choices
- Strong tools for maps, effects, and cameras
- Better for larger, more detailed games
| Feature | Kaplay | Phaser 3 |
|---|---|---|
| Setup time | โก 1 line | โฑ 10 min |
| Learning curve | โ Gentle | โ Moderate |
| Physics quality | โ Basic/Medium | โ Advanced |
| Documentation | โ Good | โ Excellent |
| Community size | โ Medium | โ Large |
| Game Jam speed | โ Useful fit | โ Also possible |
| Large projects | โ Also possible | โ Useful fit |
3How a scene starts and runs
A scene is one part of a game, such as the menu, a level, or the game-over screen. A common Phaser 3 scene uses these lifecycle methods (an optional init() can come first). Loading and setup happen when the scene starts; update repeats while it runs:
sounds ready
and add the player
check collisions
Kaplay does these jobs too, but hides more of the setup. You create a scene, use add() to place objects, and Kaplay keeps the game running.
Every engine has the same three jobs: a place for the level's objects, setup that runs once, and an update that runs every frame. Pick engines below to see what each one calls them.
update().4Compare the code
These are partial API sketches, not complete playable games: the floor and collision setup are omitted. Switch tabs and match each instruction to the frame lab. Kaplay also needs setGravity() for falling; Phaser needs a floor collider or world bounds for blocked.down to become true.
// Kaplay โ minimal setup, very readable kaplay(); scene("game", () => { // create a player with components const player = add([ rect(32, 32), // draw a 32ร32 rectangle pos(200, 200), // starting position color(BLUE), // color it blue area(), // enable collision detection body(), // enable gravity/physics "player", // tag for collision queries ]); // movement โ checked every frame automatically onKeyDown("left", () => player.move(-200, 0)); onKeyDown("right", () => player.move( 200, 0)); onKeyPress("up", () => player.jump()); }); go("game");
// Phaser 3 โ explicit scene class, more structured class GameScene extends Phaser.Scene { preload() { // load assets here โ images, tilemaps, audio } create() { // create player as a rectangle physics body this.player = this.add.rectangle(200, 200, 32, 32, 0x3b82f6); this.physics.add.existing(this.player); this.player.body.setGravityY(400); // set up cursor keys this.cursors = this.input.keyboard.createCursorKeys(); } update() { const body = this.player.body; body.setVelocityX(0); if (this.cursors.left.isDown) body.setVelocityX(-200); if (this.cursors.right.isDown) body.setVelocityX( 200); if (this.cursors.up.isDown && body.blocked.down) body.setVelocityY(-500); } } new Phaser.Game({ scene: GameScene, physics: { default: 'arcade' } });
(200, 200) and movement speed 200 in both examples. Which version is easier for you to read?5Four key words
6Choose your engine
Choose based on your situation:
Check the engine documentation
Follow the documentation for the version your project uses. This lesson compares Kaplayโs component approach with Phaser 3 scenes.
- Kaplay: creating your first game โ components, gravity, and jumping.
- Phaser: scenes โ lifecycle and scene organization.
- Phaser: your first game โ complete setup, platforms, and collisions.