phaser3-reactdom
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

phaser3-reactdom

Using React in the Phaser3 engine

Configure phaser3-reactdom plugin

import { PhaserReact, PhaserSceneReact } from "phaser3-reactdom";

const game = new Phaser.Game({
  // ...
  dom: { createContainer: true },
  // ...
  plugins: {
    global: [
      // ...
      {
        key: "phaser3-reactdom",
        plugin: PhaserReact,
        start: true,
      }
    ],
    scene: [
      // ...
      {
        key: "phaser3-reactdom-scene",
        plugin: PhaserSceneReact,
        start: true,
      }
    ],
    // ...
  },
  // ...
})

Using React

class ExampleScene extends Phaser.Scene {
  // ...
  create() {
    // The topUI will not be destroyed during scene destruction.
    const topUI = this.add.reactDom(ComponentTopUI, { state: ... });
    // ...

    // The sceneUI will be destroyed simultaneously as the scene is destroyed.
    this.sceneUI = this.add.sceneReactDom(ComponentSceneUI, { state: ... });
    // ...
  }
  // ...
  updateSceneUIState() {
    // Setting new state
    this.sceneUI.setState({ state: ... })
  }
}

Package Sidebar

Install

npm i phaser3-reactdom

Weekly Downloads

3

Version

1.0.4

License

Apache-2.0

Unpacked Size

40.6 kB

Total Files

19

Last publish

Collaborators

  • shixiongfei