Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is Phaser? A Tour of the HTML5 Game Framework

Learn what the Phaser game framework is, what it gives you, how a game is organized into scenes and game objects, and run your first live Phaser example.

Phaser is a free, open-source framework for making 2D games that run in a web browser. You write JavaScript, Phaser draws to a <canvas> element, plays sound, reads the keyboard, mouse, touch screen and gamepad, simulates physics, and animates sprites. The same game then runs on desktop, phones and tablets, because every one of them has a browser. It can also be wrapped as a desktop or mobile app, which you will see later in this track.

This lesson gives you the big picture: what Phaser is for, what is inside it, how a game is structured, and which version this course uses. At the end you will run a small game and read every line of it.

What runs on this site. Every html example in this track loads Phaser from a CDN inside a sandboxed preview and really runs. Anything that needs a build tool or a web server (Vite, npm, publishing, testing on a phone) is shown as read-only code, and the lesson says so. The preview has no access to cookies or storage, so saved-game examples print what they would store instead.

What Phaser gives you

A browser alone can already draw and listen for clicks. A game needs much more, and writing all of it from scratch is slow. Phaser supplies the repeated work:

What is inside Phaser

Rendering WebGL or Canvas, picked for you
Input Keyboard, mouse, touch, gamepad
Animation Sprite frames, tweens, timelines
Physics Arcade (simple and fast) and Matter

One framework, one game loop, one consistent API.

1 / 2

Phaser is not a game engine with a visual editor. There is no drag-and-drop window; you build the game in code and in any editor you like. That makes it a good fit if you already know some JavaScript and want full control.

A game is a tree of simple parts

Phaser organizes everything into a small number of ideas. If you remember these, the rest of the course is detail:

flowchart TD
  G["Game<br/>one per page"] --> S1["Scene: Menu"]
  G --> S2["Scene: Level 1"]
  S2 --> O1["Game objects<br/>sprites, text, shapes"]
  S2 --> O2["Systems<br/>input, physics, tweens, camera"]

A Game contains Scenes. A Scene contains game objects and the systems that work on them.

  • Game: the single object that starts everything. It owns the canvas, the renderer and the game loop.
  • Scene: one screen of your game, such as a menu, a level or a game-over screen. A scene has its own objects and runs its own code.
  • Game object: anything that can be added to a scene: a sprite, an image, a line of text, a rectangle, a particle emitter.
  • Systems (also called plugins): input, physics, tweens, timers, cameras, sound. Each scene gets its own set.

You will meet each of these properly in the next lessons. For now it is enough to know that your code almost always lives inside a scene.

The game loop in one paragraph

A game is not a program that runs once and ends. It repeats a cycle about 60 times per second: read input, update the world (move things, check hits), and draw the result. Phaser runs that cycle for you and calls your update method every frame. You describe what should change; Phaser handles the timing. The game loop gets its own lesson.

Which Phaser version does this course use?

This track uses Phaser 4 (the examples are loaded as [email protected]). Phaser 4 keeps the friendly API that Phaser 3 made popular: scenes, this.add, this.physics, this.tweens. What changed is mostly underneath, in the new WebGL renderer, which is faster and easier to extend. Almost everything you learn here also works in Phaser 3 tutorials and code you find online. Where Phaser 4 is different, the lesson says so.

Your first live game

Time to see it. The example below creates a game with one scene. The scene draws a title, a colored rectangle and a ball that bounces under gravity. Read it first, then press Run and watch the ball.

Hello Phaser: a bouncing ball

Let us walk through what happened.

  1. The <script src="...phaser.min.js"> tag loads the library and defines a global called Phaser.
  2. class HelloScene extends Phaser.Scene defines a scene. Phaser calls its create method once, after the scene starts.
  3. Inside create, this.add is the game object factory. this.add.text(...) and this.add.rectangle(...) create objects and put them on screen immediately.
  4. We drew a circle with a Graphics object, froze it as a texture named ball with generateTexture, and removed the helper. Making textures in code means this example needs no image files.
  5. this.physics.add.image makes an image that Arcade Physics moves. The gravity in the config pulls it down; setBounce and setCollideWorldBounds make it rebound off the edges of the game area.
  6. new Phaser.Game({...}) is the entry point. The object you pass is the game configuration: size, renderer type, where to put the canvas, physics settings and the list of scenes.

Notice that nothing moves the ball in your code. Physics does it, and Phaser calls the physics step every frame. That separation is typical: you set up objects in create and let the systems drive them.

Coordinates: where is (0, 0)?

Phaser, like most 2D browser APIs, puts the origin (0, 0) in the top-left corner. x grows to the right and y grows down. This surprises people who remember graphs from math class, where y goes up. Keep it in mind: to move an object down, you add to y.

Coordinates and origin

By default Phaser positions most objects by their center, because their origin is (0.5, 0.5). Text is the exception: it uses the top-left corner. You will change origins with setOrigin in Images and Sprites.

Strengths, limits and what to expect

Phaser is a very good fit for 2D games: platformers, shooters, puzzle games, card games, arcade classics, educational games, game jams and prototypes. It has a large community, a long history and plenty of examples.

It is not meant for heavy 3D (use Three.js or Babylon.js for that), and it does not ship an editor, a level designer or a store. For levels you can use the free Tiled editor (Tilemaps), and for packaging you use ordinary web and app tooling.

Because games run in the browser, three practical facts shape how you work:

  • Assets load over the network. Images and sounds are files fetched by the browser, so you wait for them in a preload step before you use them.
  • Audio needs a user gesture. Browsers refuse to play sound until the player clicks or presses a key once.
  • Performance is limited by the slowest device you support. Phones are weaker than desktops, so you keep an eye on how many objects you draw.

Common beginner mistakes

  • Forgetting new Phaser.Game. Defining a scene class does nothing until a game is created with that scene in its config.
  • Using an asset before it is loaded. If you call this.add.image('hero', ...) without loading hero, Phaser draws a green box with a cross; you will see this "missing texture" in many early mistakes.
  • Assuming y goes up. It goes down.
  • Putting everything in one giant file. It works at first. Later lessons show how to split a game into scene files.

When something does not appear, open the browser developer console. Phaser prints clear warnings for missing keys and bad config values.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Phaser draw its graphics into?

    Phaser renders to a canvas using WebGL (preferred) or the 2D Canvas API, and creates that canvas for you.
  2. 2. Which part of Phaser represents one screen of a game, such as a menu or a level?

    A Scene holds its own game objects and systems. Games switch between scenes such as Menu, Level and GameOver.
  3. 3. In Phaser's coordinate system, how does y change as you move down the screen?

    The origin is the top-left corner, x increases to the right and y increases downward.
  4. 4. What does the object passed to new Phaser.Game({...}) contain?

    The game configuration tells Phaser how big the game is, where to put the canvas, which physics to use and which scenes to run.

Summary

  • Phaser is a free 2D game framework for the browser; it handles rendering, input, animation, physics, audio and loading.
  • A Game contains Scenes, and a Scene contains game objects plus systems such as input, physics and tweens.
  • You create everything from a game configuration passed to new Phaser.Game.
  • The origin (0, 0) is the top-left corner and y grows downward; most objects are positioned by their center.
  • This course uses Phaser 4 ([email protected]) and keeps examples compatible with Phaser 3 wherever possible.

Next: Your First Phaser Game