onEnable的时机太早了,对象加到场景中就会调用onEnable,这时候图片还没有下载完成
必须要保证图片下载设置完成才能调用drawToTexture,例如
onEnable(): void {
const { x, y, width, height } = this.box
Laya.loader.load('comp/image.png').then(v=>{
const texture = this.box.drawToTexture(width, height, x, y) as Laya.Texture
this.snapshot.texture = texture
});
}