1
- import React , { useState , useEffect } from 'react'
1
+ import React , { useState , useEffect , useRef } from 'react'
2
2
import Phaser from 'phaser'
3
3
import { IonPhaser , GameInstance } from '@ion-phaser/react'
4
4
import logo from './assets/logo.png'
@@ -18,7 +18,7 @@ class MainScene extends Phaser.Scene {
18
18
this . cameras . main . centerY ,
19
19
"Hello World" , {
20
20
font : "40px Arial" ,
21
- fill : "#ffffff"
21
+ color : "#ffffff"
22
22
}
23
23
) ;
24
24
this . helloWorld . setOrigin ( 0.5 ) ;
@@ -54,11 +54,12 @@ const gameConfig: GameInstance = {
54
54
} ;
55
55
56
56
export default function App ( ) {
57
+ const gameRef = useRef < HTMLIonPhaserElement > ( )
57
58
const [ game , setGame ] = useState < GameInstance > ( )
58
59
const [ initialize , setInitialize ] = useState ( false )
59
60
60
61
const destroy = ( ) => {
61
- console . log ( 'Instance' , game ?. instance )
62
+ gameRef . current ?. destroy ( )
62
63
setInitialize ( false )
63
64
setGame ( undefined )
64
65
}
@@ -74,7 +75,7 @@ export default function App () {
74
75
< header className = "App-header" >
75
76
{ initialize ? (
76
77
< >
77
- < IonPhaser game = { game } initialize = { initialize } />
78
+ < IonPhaser ref = { gameRef } game = { game } initialize = { initialize } />
78
79
< div onClick = { destroy } className = "flex destroyButton" >
79
80
< a href = "#1" className = "bttn" > Destroy</ a >
80
81
</ div >
0 commit comments