Skip to content

Commit 5bf5d37

Browse files
committed
Fix demo-react project to get the instance
1 parent d036903 commit 5bf5d37

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

demo-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@ion-phaser/react": "file:../react",
6+
"@ion-phaser/react": "^1.2.2",
77
"@types/jest": "^25.2.1",
88
"@types/node": "^13.13.4",
99
"@types/react": "^16.9.34",

demo-react/src/App.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import Phaser from 'phaser'
3-
import { IonPhaser } from '@ion-phaser/react'
3+
import { IonPhaser, GameInstance } from '@ion-phaser/react'
44
import logo from './assets/logo.png'
55

66
import './App.css'
@@ -28,7 +28,7 @@ class MainScene extends Phaser.Scene {
2828
}
2929
}
3030

31-
const game: Phaser.Types.Core.GameConfig = {
31+
const gameConfig: GameInstance = {
3232
width: "100%",
3333
height: "100%",
3434
type: Phaser.AUTO,
@@ -53,11 +53,22 @@ const game: Phaser.Types.Core.GameConfig = {
5353
scene: MainScene
5454
};
5555

56-
const destroy = () => window.location.reload()
57-
5856
export default function App () {
57+
const [game, setGame] = useState<GameInstance>()
5958
const [initialize, setInitialize] = useState(false)
6059

60+
const destroy = () => {
61+
console.log('Instance', game?.instance)
62+
game?.instance?.destroy(true)
63+
setInitialize(false)
64+
}
65+
66+
useEffect(() => {
67+
if (initialize) {
68+
setGame(Object.assign({}, gameConfig))
69+
}
70+
}, [initialize])
71+
6172
return (
6273
<div className="App">
6374
<header className="App-header">

0 commit comments

Comments
 (0)