我使用“相位器”,‘离子-相位’和一个相位插件‘网格引擎’整合一个相位游戏的反应。我可以成功地初始化游戏,然后销毁它,没有错误。但是,当我尝试重新初始化它时,İ不会给出两个错误
Scene Plugin key in use: GridEngine 和
Uncaught TypeError: Cannot read properties of undefined (reading 'create')
at Scene.create (isometric.js:93: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)这一行的第二个错误
this.gridEngine.create(cloudCityTilemap, gridEngineConfig);此外,当我尝试一个没有插件,如网格引擎的相位游戏,没有错误。我搜索,我认为我必须删除网格引擎插件时,破坏游戏,但我找不到办法。我的问题是
如何销毁包含插件的相位游戏并重新启动它?
这是代码示例
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>
</>
)
}最后,我想在同一个页面上更改不同的游戏或级别。
发布于 2022-11-03 19:09:29
我不能百分之百肯定,如果这能解决你所有的问题,但是
<button onClick={setInitialize(true)}>是不正确的,你不应该调用函数,你应该只传递它。试着用
<button onClick={ () => setInitialize(true)}> 有关详细信息,请查看此条款/文件获取详细信息。
更新:如何获取游戏对象
要获得Phaser游戏对象,您必须使用getInstance (链接到离子相位器文档)并删除插件,您必须这样做:
this.gameRef.current.getInstance()
.then(game => game.plugins.removeScenePlugin("GridEngine"))https://stackoverflow.com/questions/74295268
复制相似问题