File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 3
3
"version" : " 0.1.0" ,
4
4
"private" : true ,
5
5
"dependencies" : {
6
- "@ion-phaser/react" : " file:../react " ,
6
+ "@ion-phaser/react" : " ^1.2.2 " ,
7
7
"@types/jest" : " ^25.2.1" ,
8
8
"@types/node" : " ^13.13.4" ,
9
9
"@types/react" : " ^16.9.34" ,
Original file line number Diff line number Diff line change 1
- import React , { useState } from 'react'
1
+ import React , { useState , useEffect } from 'react'
2
2
import Phaser from 'phaser'
3
- import { IonPhaser } from '@ion-phaser/react'
3
+ import { IonPhaser , GameInstance } from '@ion-phaser/react'
4
4
import logo from './assets/logo.png'
5
5
6
6
import './App.css'
@@ -28,7 +28,7 @@ class MainScene extends Phaser.Scene {
28
28
}
29
29
}
30
30
31
- const game : Phaser . Types . Core . GameConfig = {
31
+ const gameConfig : GameInstance = {
32
32
width : "100%" ,
33
33
height : "100%" ,
34
34
type : Phaser . AUTO ,
@@ -53,11 +53,22 @@ const game: Phaser.Types.Core.GameConfig = {
53
53
scene : MainScene
54
54
} ;
55
55
56
- const destroy = ( ) => window . location . reload ( )
57
-
58
56
export default function App ( ) {
57
+ const [ game , setGame ] = useState < GameInstance > ( )
59
58
const [ initialize , setInitialize ] = useState ( false )
60
59
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
+
61
72
return (
62
73
< div className = "App" >
63
74
< header className = "App-header" >
You can’t perform that action at this time.
0 commit comments