Phaser - 清理 loadState 和 bootState 缓存 DOM

Phaser - Clean loadState and bootState cache DOM

我用 Phaser.js 制作了一个游戏。我想清除所有 loadStatebootState 缓存 DOM,以删除图像 link.

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

当我使用Phaser.Cache

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

Game缓存结果被清理

image Object { __default={...}, __missing={...}} __default Object { key="__default", data=img, base={...}, plus...} __missing Object { key="__missing", data=img, base={...}, plus...}

但是loadStatebootState缓存还在

image Object { __default={...}, __missing={...}, background2={...}, plus...} __default Object { key="__default", data=img, base={...}, plus...} __missing Object { key="__missing", data=img, base={...}, plus...} background Object { key="background", url="data:image/jpeg;base64,/...q0xYqtMOKrDFiqz0sVf/9k=", data=img, plus...}

你需要清除每个状态

game.state.clearCurrentState(); 

phaser 文档说:

This method clears the current State, calling its shutdown callback. The process also removes any active tweens, resets the camera, resets input, clears physics, removes timers and if set clears the world and cache too.

你也可以使用

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