我目前用的是CocosCreator3.4
使用代码:
initTexture() {
// 存储 Uint8Array 数据,存入 imageAsset, 然后通过 texture2D.image = imageAsset创建texture2D,
// 之后把texture2d 赋值给Sprite渲染。
this.imageAsset = new ImageAsset();
this.imageAsset.reset({
width: this.drawNode.getComponent(UITransform).width,
height: this.drawNode.getComponent(UITransform).height,
close: null
});
this.texture2d = new Texture2D();
this.texture2d.reset({
width: this.imageAsset.width,
height: this.imageAsset.height,
format: Texture2D.PixelFormat.RGBA8888
});
this.texture2d.image = this.imageAsset;
let spf: SpriteFrame = new SpriteFrame();
spf.texture = this.texture2d;
this.drawNode.getComponent(Sprite).spriteFrame = spf;
}
当this.drawNode使用330* 310的时候报错:
当this.drawNode分辨率800* 600的时候是好的
