renderer.destroySkin()
销毁造型并释放其资源。调用此方法后不要使用造型或其 ID。
语法
renderer.destroySkin(skinId)
参数
skinId
类型: number
要销毁的造型的 ID。
返回值
类型: void
示例
class SkinManagerExtension {
constructor(runtime) {
this.runtime = runtime;
this.customSkins = new Map();
// 在项目停止时清理
runtime.on('PROJECT_STOP_ALL', () => {
this.cleanup();
});
}
cleanup() {
const renderer = this.runtime.renderer;
// 销毁所有自定义造型
for (const skinId of this.customSkins.values()) {
renderer.destroySkin(skinId);
}
this.customSkins.clear();
}
}
重要注意事项
- 内存管理 - 不再需要造型时始终销毁它们
- 可绘制对象引用 - 销毁被可绘制对象使用的造型可能导致渲染问题
- 最佳实践 - 在销毁造型之前恢复可绘制对象的造型
另请参阅
- createBitmapSkin() - 创建位图造型
- createSVGSkin() - 创建 SVG 造型
- 资源管理 - 清理最佳实践