Use events to pass data between Scenes for decoupled code.

Posted on 7th Jul 2021. Follow @phaser_ and get the Phaser World newsletter.

image

Tommy Leung from Ourcade writes: "Are you using modern JavaScript and splitting your Phaser 3 game code into multiple files? 👏

One common best practice is to put the UI code in a separate Scene.

But then how are you supposed to give the UI Scene information like player health or score?

How would a pause button in the UI Scene tell the Game Scene to pause?

One solution is to pass data using events.

The easiest way to implement this is to use the EventEmitter instance from this.game.events but…"

Read More

Learn to code and lead your intrepid crew on a mission to save The Cloud in TwilioQuest, a PC role-playing game inspired by classics of the 16-bit era. Free forever, and available now for Windows, Mac, and Linux.

The first book on the creation of HTML5 cross platform games using Phaser 3 and other free software.
  • By Emanuele Feronato
  • 155 Pages
  • 28 Source Code Examples
  • Build a complete game from start to finish
  • Cross Platform
  • Scaling for devices
Buy Now
$19