Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not reinitialize after destroy becauseof plugin #50

Open
Sinanaltundag opened this issue Nov 3, 2022 · 1 comment
Open

can not reinitialize after destroy becauseof plugin #50

Sinanaltundag opened this issue Nov 3, 2022 · 1 comment

Comments

@Sinanaltundag
Copy link

Sinanaltundag commented Nov 3, 2022

I try with a simple example like in this repo, there is not a problem but in my project I use grid-engine plugin, and when I try to initialize after destroy gameRef, this 2 errors occured.

Scene Plugin key in use: GridEngine 
    at ReactComponent (http://localhost:3000/static/js/bundle.js:1437:7)
    at IonPhaser
    at header
    at div
    at IonEx (http://localhost:3000/static/js/bundle.js:409:64)
    at div
    at App
Uncaught TypeError: Cannot read properties of undefined (reading 'create')
    at MainScene.create (ionexample.jsx:50:1)
    at SceneManager.create (phaser.js:84684:1)
    at SceneManager.loadComplete (phaser.js:84615:1)
    at LoaderPlugin.emit (phaser.js:1671:1)
    at LoaderPlugin.loadComplete (phaser.js:165337:1)
    at LoaderPlugin.fileProcessComplete (phaser.js:165311:1)
    at SpriteSheetFile.onProcessComplete (phaser.js:4290:1)
    at data.onload (phaser.js:16548:1)

second error at this line
this.gridEngine.create(cloudCityTilemap, gridEngineConfig);
how can I reinitialize my game after destroy it

@Sinanaltundag
Copy link
Author

this is my code sample

          const game = {
        width: 800,
        height: 600,
        type: Phaser.AUTO,
        scene: {
          preload,
          create,
          update,
        },
        plugins: {
          scene: [
            {
              key: 'GridEngine',
              plugin: GridEngine,
              mapping: 'gridEngine'
            },
          ],
        },
      }
  const gameRef = useRef(null)
  const [initialize, setInitialize] = useState(false)
  const destroy = () => {
    if (gameRef.current) {
      gameRef.current.destroy()
    }
    setInitialize(false)
  }
  return (
    <>
      <IonPhaser game={game}  ref={gameRef} initialize={initialize} />
      <button onClick={setInitialize(true)}>Initialize</button>
      <button onClick={destroy}>Destroy</button>
    </>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant