如何完全删除Pixi渲染器,舞台和资产
How to completely remove Pixi renderer, stage and assets?
我正在尝试用React安装/卸载Pixi stage(我不想使用React - Pixi)
重新挂载组件时出现错误:
Uncaught Error: Resource with name "cupCake.png" already exists
i.add.i.enqueueapp.js
componentDidMountmodules.js
_assign.notifyAllmodules.js
ON_DOM_READY_QUEUEING.closemodules.js
Mixin.closeAllmodules.js
Mixin.performmodules.js
Mixin.performmodules.js
_assign.performmodules.js
flushBatchedUpdatesmodules.js
Mixin.closeAllmodules.js
Mixin.performmodules.js
ReactDefaultBatchingStrategy.batchedUpdatesmodules.js
batchedUpdatesmodules.js
ReactEventListener.dispatchEvent
我尝试使用:PIXI.TextureCache['cupCake.png'].destroy(true);
,但错误仍然存在。
这是我的组件:
class MapOverlay extends React.Component{
constructor(props) {
super(props);
}
componentDidMount() {
this.renderer = PIXI.autoDetectRenderer(256, 256, {transparent: true});
this.refs.gameCanvas.appendChild(this.renderer.view);
// create the root of the scene graph
this.stage = new PIXI.Container();
this.stage.width = 1366;
this.stage.height = 768;
PIXI.loader
.add("cupCake.png")
.load(()=> {
//Create the `cat` sprite from the texture
var cat = new PIXI.Sprite(
PIXI.loader.resources["cupCake.png"].texture
);
//Add the cat to the stage
this.stage.addChild(cat);
//Render the stage
this.renderer.render(this.stage);
});
}
componentWillUnmount() {
this.refs.gameCanvas.removeChild(this.renderer.view);
PIXI.TextureCache['cupCake.png'].destroy(true);
}
render() {
return (
<div className="game-canvas-container" ref="gameCanvas"></div>
);
}
}
那么我如何才能完全重置/删除状态和资产呢?
答案是使用最新的v4版本的PIXI
删除纹理的最好方法是调用this.stage.destroy(true);
this.stage = null;
这将破坏舞台,它的所有子节点,以及它的任何子节点正在使用的任何纹理。
在做
之后this.refs.gameCanvas.removeChild(this.renderer.view);
添加
this.renderer.destroy( true );
this.renderer = null;
相关文章:
- 定义完全独立的样式信息
- 完全可链接的li元素
- 如何在内联依赖项并将图像转换为dataURI的情况下完全提取网页
- Jquery/Ajax.serialize()未完全工作
- 处理一个JSON文件;完全相同的副本不是
- “createImageData()”和“new ImageData(()”有何不同
- 如何从mac上完全删除Ionic和Cordova安装
- HtmlUnit无法在youtube上完全加载页面
- 如何放置单独的ajax调用,使页面的一部分完全响应,而另一部分仍在加载
- 将broccoliJS与当前使用requireJS的模块化主干应用程序结合使用,我想完全放弃requireJS
- 谷歌地图完全放大
- 如何在特定条件下完全禁用FullPage.js
- 多人游戏完全在浏览器中运行,服务器仅用于数据库
- 引导程序导航栏don't完全打开
- YepNopeJS:在小JS文件完全加载之前触发回调
- 如何在iframe中找到与页面上的元素完全相同的元素
- Jquery abort()没有'似乎没有完全释放
- 函数未完全循环通过循环
- 完全限制输入字段上的输入
- 如何完全删除Pixi渲染器,舞台和资产