Phaser
20 minutes
linux
macos
windows

What is Phaser?

Learn what Phaser is, what types of games you can build, and the core concepts of game development.

What you'll accomplish

Understand what Phaser is and core game development concepts.

Prerequisites

  • Basic JavaScript/TypeScript knowledge
  • Node.js installed
  • No game development experience required

What is Phaser?

Phaser is a JavaScript game framework for making 2D games that run in web browsers. No downloads, no installs - players just open a URL and play.

Imagine you want to build a treehouse. You could:

  1. Chop down trees, mill lumber, forge nails... (hard!)
  2. Go to the hardware store and buy ready-made parts (easier!)

Phaser is like that hardware store for games. It gives you:

  • Ready-made pieces (sprites, physics, sound)
  • Tools to assemble them (the game engine)
  • Instructions (documentation)

You focus on making your game fun. Phaser handles the technical parts.

What Can You Build?

Phaser excels at 2D games:

Game TypeExamples
PlatformersMario-style jumping games
Puzzle GamesMatch-3, Tetris, logic games
ShootersSpace shooters, bullet hell
RPGsTop-down adventure games
Card GamesSolitaire, poker, card battles
Endless RunnersTemple Run style
Physics GamesAngry Birds style

Real Phaser Games

Many successful games are built with Phaser:

  • Agar.io - Multiplayer cell eating game
  • Slither.io - Snake-style multiplayer
  • Countless browser games on gaming sites

Why Phaser?

FeatureBenefit
Web-basedNo downloads, instant play
Cross-platformWorks on any device with a browser
Free & Open SourceNo licensing fees
Large CommunityLots of tutorials and examples
TypeScript SupportType safety and IDE support
Active DevelopmentRegular updates and improvements

Phaser vs. Other Options

ToolBest For
Phaser2D browser games, quick prototypes
Unity3D games, complex games, mobile
Godot2D/3D games, open source
GameMaker2D games, visual programming
ConstructNo-code 2D games

Choose Phaser when:

  • You know JavaScript/TypeScript
  • You want games to run in browsers
  • You're building 2D games
  • You want free, open-source tools

Core Game Development Concepts

Before diving into code, understand these fundamentals:

The Game Loop

Every game runs a continuous loop:

┌─────────────────────────────┐
│                             │
│  1. Process Input           │
│     (keyboard, mouse)       │
│            ↓                │
│  2. Update Game State       │
│     (physics, logic)        │
│            ↓                │
│  3. Render Graphics         │
│     (draw everything)       │
│            ↓                │
│  Repeat 60 times/second     │
│                             │
└─────────────────────────────┘

This happens 60 times per second (60 FPS), creating smooth animation.

Movies run at 24 frames per second and look smooth. Games target 60 FPS because:

  1. You're interacting, so lag is more noticeable
  2. Higher frame rates feel more responsive
  3. Modern screens refresh at 60Hz (60 times per second)

Each "frame" is a complete picture. 60 pictures per second = smooth motion.

Sprites

A sprite is any visual object in your game:

  • Player character
  • Enemies
  • Bullets
  • Coins
  • Background elements

Sprites are images positioned on the screen. They can move, animate, and interact.

Physics

Physics systems simulate real-world behavior:

  • Gravity: Objects fall down
  • Velocity: Speed and direction
  • Collision: Objects can hit each other
  • Bounce: Objects can bounce off surfaces

Phaser includes physics engines that handle this automatically.

Scenes

Games are organized into scenes (like screens):

  • Main menu
  • Gameplay
  • Pause menu
  • Game over screen

Each scene has its own logic and can transition to others.

Assets

Assets are the resources your game uses:

  • Images: Sprites, backgrounds, UI
  • Audio: Sound effects, music
  • Data: Level data, high scores

You load assets before using them.

Your First Look at Phaser Code

Here's a simple Phaser game structure:

typescript
import Phaser from 'phaser';

class MainScene extends Phaser.Scene {
  constructor() {
    super('MainScene');
  }

  preload() {
    // Load assets
    this.load.image('player', 'player.png');
  }

  create() {
    // Set up game objects
    this.add.image(400, 300, 'player');
  }

  update() {
    // Game loop - runs every frame
    // Handle input, update positions, etc.
  }
}

const config: Phaser.Types.Core.GameConfig = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  scene: MainScene,
};

new Phaser.Game(config);

Key parts:

  • preload(): Load images, sounds, etc.
  • create(): Set up game objects once
  • update(): Run every frame (60x per second)

Don't worry about understanding everything yet - we'll build this up step by step!

What You'll Build in This Track

By the end of this track, you'll:

  1. Set up a Phaser project with modern tooling
  2. Create scenes with proper lifecycle management
  3. Add sprites and animate them
  4. Implement physics for movement and collision
  5. Add audio for effects and music
  6. Build a complete game you can share

Hardware Requirements

Phaser games are lightweight. You don't need powerful hardware:

To develop:

  • Any modern computer
  • Node.js installed
  • A code editor (VS Code/Cursor)

To play:

  • Any device with a modern browser
  • Even mobile phones work!

Common Questions

Frequently Asked Questions

Basic math helps (addition, multiplication), but Phaser's physics engines handle complex calculations. You mostly configure values like "gravity: 300" and Phaser does the rest.

Yes! Options include:

  • Ad-supported browser games
  • Premium games on itch.io
  • Game licensing to portals
  • Wrap in Capacitor for app stores
  • Client work and freelancing

Phaser is excellent for beginners because:

  • Web-based (easy to share and test)
  • Strong documentation
  • Instant feedback (refresh browser)
  • No complex installations

Phaser is designed for 2D. For 3D, consider:

  • Three.js (3D web)
  • Babylon.js (3D web)
  • Unity/Godot (full engines)

Some games fake 3D with 2D sprites (isometric view).

It depends on scope:

  • Simple game jam game: 1-3 days
  • Small polished game: 1-4 weeks
  • Complex game: Months to years

Start small! Complete a tiny game before attempting big projects.

Verify Your Understanding

You've completed this lesson if you can:

0/5

Next: Set up a Phaser project with Vite and TypeScript.