相位器-清洁loadState和bootState缓存DOM



我用Phaser.js制作了一款游戏。我想清理所有loadStatebootState缓存DOM,删除图像链接。

我实际上使用Phaser.Cache来删除Game DOM中的所有缓存,它工作,但loadStatebootState缓存仍然存在。

当我使用相位器时。缓存

game.cache = new Phaser.Cache(game);
game.load.reset();
game.load.removeAll();

Game缓存结果被清理

image Object {__default={…}, __missing ={…}}__default对象{key="__default", data=img, base={…} +…}__missing Object {key="__missing", data=img, base={…} +…}

但是loadStatebootState缓存还在

image Object {__default={…__missing ={…}},background2 ={…} +…}__default对象{key="__default", data=img, base={…} +…}__missing Object {key="__missing", data=img, base={…},加上…} background对象{key="background",url = "数据:图像/jpeg, base64/……q0xYqtMOKrDFiqz0sVf/9 k = " data = img,+…}

您需要清除每个状态

game.state.clearCurrentState(); 

相位器文档说:

此方法通过调用其shutdown回调来清除当前状态。这个过程也会删除任何活动的渐变,重置相机,重置输入,清除物理,删除计时器,如果设置清除世界和缓存。

也可以用

game.state.destroy(); // Removes all StateManager callback references to the State object, nulls the game reference and clears the States object

最新更新