renderer.destroySkin()
销毁一个皮肤并释放其资源。调用此方法后,请勿再使用该皮肤或其 ID。
语法
renderer.destroySkin(skinId)
参数
skinId
类型: number
要销毁的皮肤 ID。
返回值
类型: void
示例
class SkinManagerExtension {
constructor(runtime) {
this.runtime = runtime;
this.customSkins = new Map();
// Clean up on project stop
runtime.on('PROJECT_STOP_ALL', () => {
this.cleanup();
});
}
cleanup() {
const renderer = this.runtime.renderer;
// Destroy all custom skins
for (const skinId of this.customSkins.values()) {
renderer.destroySkin(skinId);
}
this.customSkins.clear();
}
}
重要说明
- 内存管理 - 不再需要时一定要销毁皮肤
- 可绘制对象引用 - 销毁被可绘制对象使用的皮肤可能导致渲染问题
- 最佳实践 - 在销毁皮肤之前,先恢复(还原)使用该皮肤的可绘制对象
另请参阅
- createBitmapSkin() - 创建位图皮肤
- createSVGSkin() - 创建 SVG 皮肤
- 资源管理 - 清理的最佳实践