Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 36 ยท Packaging and Publishing

Optimizing and Publishing Your Game

Measure and improve Phaser performance with atlases, batching and pooling, then publish your game to itch.io, static hosts, portals, mobile and desktop.

A game that runs at 60 frames per second on your development laptop can crawl on a three-year-old phone, and a game that is fast but takes 40 seconds to download will lose most players before the first screen. Optimization means two separate things: runtime speed (frames per second, memory) and delivery (download size, hosting, caching). Then comes the part that makes all the work visible: publishing the game where players can find it.

This lesson gives you a practical routine: measure first, fix the few things that matter in Phaser games, and ship the result to the common places: a static host, itch.io, a game portal, and as a mobile or desktop app.

Measure before you optimize

Guessing which part is slow wastes time. Phaser gives you a built-in clock, and the browser gives you a profiler.

  • this.game.loop.actualFps is the smoothed frames per second; this.game.loop.delta is the length of the last frame in milliseconds.
  • The fps option in the game config can show a target (fps: { target: 60 }), and the Arcade Physics debug: true flag draws bodies and shows how many exist.
  • Chrome and Edge DevTools, Performance tab: record a few seconds and look for long frames (red marks), scripting time, and garbage collection spikes.
  • DevTools Memory tab: take heap snapshots to find objects that grow without bound (a leak).
  • The Rendering panel has an FPS meter and a paint flashing option.

Test on the weakest device you care about, or throttle the CPU in DevTools (4 to 6 times slower) to imitate a phone.

What usually makes Phaser games slow

In practice, a handful of causes explain most problems:

  1. Too many draw calls. The GPU is fastest when it draws many things in one batch. Phaser's WebGL renderer batches consecutive objects that use the same texture. Switching textures breaks the batch. A scene with 40 different small images may issue 40 draw calls; the same scene from one texture atlas can be one.
  2. Creating objects in update(). Every new Phaser.Math.Vector2(), array literal or text object created each frame becomes garbage, and the garbage collector later pauses the game. Reuse objects and pool short-lived sprites (see Custom Game Objects and Object Pools).
  3. Too many active objects. Thousands of physics bodies, many animated sprites, or huge particle emitters cost CPU. Remove or deactivate objects that left the screen; use setActive(false) and setVisible(false).
  4. Large textures. A 4096 by 4096 image uses 64 MB of video memory uncompressed. Mobile GPUs have limits and share memory. Keep atlases to 2048 by 2048 where you can and downscale art that is bigger than it appears on screen.
  5. Expensive effects. Many post-processing pipelines, full-screen shaders, blend modes, masks and lights each add a pass. Use them sparingly, especially on mobile.
  6. Heavy text updates. setText re-renders the text to a canvas and uploads it as a texture. Update text only when the value changes, not every frame, or use bitmap text.
  7. Collisions with large groups. Colliding every bullet with every enemy is a quadratic cost. Use physics.add.overlap with groups only where needed, and keep the group sizes small by pooling.

Texture atlases and batching

A texture atlas packs many small images into one big texture plus a JSON file listing where each frame is. Tools such as TexturePacker or the free Free Texture Packer produce them. You load it with this.load.atlas('sprites', 'sprites.png', 'sprites.json') and use a frame with this.add.image(x, y, 'sprites', 'coin'). Benefits: fewer files to download, fewer texture switches (so more batching), and animations defined by frame names.

You can see what an atlas is without any tool: it is a texture with named rectangles. The example below draws four shapes into one texture, then defines frames on it in code (the same call Phaser makes when it parses an atlas JSON). The sprites it creates all draw from a single texture, so they batch together.

One texture, many frames

All 120 sprites come from one texture, so a WebGL renderer can draw them in a single batch. If you loaded four separate images and mixed them in random order, texture switches could split the work into many more draw calls. Sorting by texture (or by depth with texture in mind) and using atlases keeps batches long.

A stress test you can run yourself

How many sprites can your machine move? The next example adds and removes bouncing balls with buttons and shows the frame rate. It uses a single texture and no per-frame allocations, so it measures the cost of the sprites themselves. The numbers will differ on every computer, which is the point: this is how you find your own limits, and how you compare before and after an optimization.

Sprite stress test with FPS

The update loop uses a plain for...of over a stored array and does no allocation inside it. Press +2000 a few times to see where your device starts to drop below 60 fps. Then think about what a real game could cut: off-screen balls could be skipped, far-away ones could update less often, and static objects do not need update at all.

Reducing download size

  • Compress images: use lossy compression for photos and backgrounds, and palette-reduced PNG for pixel art (tools such as Squoosh, pngquant). Prefer WebP where acceptable.
  • Compress audio: 96 to 128 kbps MP3 or OGG is plenty for music; effects can be shorter and mono.
  • Atlas everything small, as above.
  • Enable gzip or Brotli on the server, which usually shrinks JavaScript and JSON by 70 percent or more.
  • Split and cache: put the engine in its own chunk and let the browser cache it.
  • Load progressively: preload only what the menu needs and load level assets when the player starts the level, with a progress bar (see Scene Architecture).

Publishing options

flowchart LR
  B["npm run build<br/>dist/ folder"] --> S["Static host<br/>Netlify, Cloudflare Pages,<br/>GitHub Pages"]
  B --> I["itch.io<br/>zip with index.html at the root"]
  B --> P["Game portals<br/>Poki, CrazyGames, ..."]
  B --> M["Mobile apps<br/>Capacitor"]
  B --> D["Desktop apps<br/>Electron, Tauri"]

One build output feeds every distribution channel.

Static hosting. The dist/ folder is static files. Netlify, Cloudflare Pages, Vercel and GitHub Pages serve it for free at small scale. Use a custom domain when you can. Set cache headers so that hashed asset files are cached for a long time (Cache-Control: public, max-age=31536000, immutable) while index.html is not cached, so players always get the newest file list.

itch.io. Zip the contents of dist/ (so index.html is at the root of the zip), create a project of type HTML, upload the zip, tick "This file will be played in the browser" and set the embed size. This works only with relative asset paths, which is why base: './' matters. itch.io hosts the game in an iframe, so test fullscreen and audio there.

Game portals. Sites such as Poki or CrazyGames bring large audiences but have their own rules: they provide an SDK for ads and events, require specific file size limits and testing, and review your game. Read their guidelines before you design monetization, and keep the SDK calls behind a small wrapper so you can switch.

Mobile apps. Capacitor wraps your web build in a native shell for iOS and Android, so you can sell in app stores. Plan for touch controls, safe areas, store art and privacy policies. Test performance on real devices; WebView performance is close to the browser, not to native engines.

Desktop and Steam. Electron or Tauri package the build as a desktop program, which is how many HTML5 games reach Steam. Electron is heavier but familiar; Tauri is much smaller.

Before you press publish

  • Play the production build from npm run preview, on a phone and in at least two browsers.
  • Check audio unlocks properly and the game pauses when the tab is hidden.
  • Save and load work (and fail gracefully without storage).
  • Credits and licenses are included for every asset, font and library you did not create. Free assets often require attribution.
  • Add a title, a short description, screenshots and a capture of the gameplay loop to the page. These sell the game more than anything else.
  • If you collect data (analytics, ads, accounts), add a privacy notice and follow the rules where your players live.
  • Give players a way to report bugs, and watch the browser console errors you can collect with a simple window.onerror handler.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main benefit of packing many small images into one texture atlas?

    The WebGL renderer batches objects that share a texture. An atlas keeps many sprites on one texture and cuts requests.
  2. 2. Why is creating new objects (vectors, arrays, text) inside update() a performance problem?

    Short-lived allocations pile up and trigger garbage collection, which shows up as random frame drops.
  3. 3. How should you structure the zip for an itch.io HTML game?

    itch.io looks for index.html at the root of the uploaded archive and serves the files from there.
  4. 4. What is the best first step when a game is slow on a phone?

    Profiling finds the real cost (draw calls, scripting, garbage collection) so that you fix the right thing.

Summary

  • Measure first: game.loop.actualFps, DevTools Performance and Memory, and testing with a throttled CPU or a real phone.
  • The usual culprits are too many draw calls, allocations in update, too many active objects, huge textures, heavy effects and constant text updates.
  • Texture atlases, pooling, culling and bitmap text address most of them.
  • Reduce download size with compressed images and audio, gzip or Brotli, chunk caching and progressive loading.
  • Publish the dist/ build to static hosts, itch.io, portals, mobile (Capacitor) or desktop (Electron, Tauri), after testing the production build and checking licenses.

Next: Project: A Platformer Game