Skip to content

Instantly share code, notes, and snippets.

@johncip
Last active March 10, 2024 08:16
Show Gist options
  • Save johncip/f7335eda50c5e0988334d904d042b084 to your computer and use it in GitHub Desktop.
Save johncip/f7335eda50c5e0988334d904d042b084 to your computer and use it in GitHub Desktop.
Moving from Phaser 2 to 3

Moving from Phaser 2 → 3: an incomplete guide

Summary

  • I found that the best thing was to ask myself what this or that line was meant to accomplish, and then to search labs.phaser.io for a Phaser 3 example of that task.
  • Usually the issue is just that a function has moved, or some property now requires a setter.
  • There's a real migration guide here: part 1, part 2

Scenes have replaced states (and the game object… mostly)

  • the default camera is now scene.cameras.main, not game.camera
  • factories are part of the scene: game.add(x)scene.add(x)
  • game.world.bringToTop(x)scene.children.bringToTop(x)

Animations now belong to a global animation manager

  • they must be created (using .create) before they're added
  • changing the frame for a sprite requires sprite.setFrame(x)
    • in fact, sprite.frame = x will break rendering for that sprite

No more sprite.exists

  • sprite.exists = xsprite.setActive(x)
    • or sprite.setVisible(x), depending on what you're trying to accomplish

Turn retrofonts into bitmapfonts

  • retrofonts are gone as a first-class thing
  • instead use RetroFont.Parse on a config object to create a bitmapfont and add that.

Changes to load.tilemap

  • game.load.tilemap(key, url, null, Phaser.Tilemap.TILED_JSON)scene.load.tilemapTiledJSON(key, url)
  • AFAICT, the ability to pass an already-loaded json tilemap (i.e. the third argument to load.tilemap) is gone. I had to let Phaser fetch my tilemaps, which in turn meant having Webpack treat them as "data" files and not JS. The procedure for that is annoyingly nonobvious.

New top-level namespaces

  • e.g. Phaser.RectanglePhaser.Geom.Rectangle
@johncip
Copy link
Author

johncip commented Jul 12, 2019

Hope it helps!

I took a break from my (small amount of) Phaser stuff, but I don't imagine much will change in that time.

And be sure to look at the linked migration guide as it mentions some big things that I've left out (center-alignment is the default in v3, nested groups are gone, and more).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment