需要自己绘制一张纯色的图片,目前测试是把这张绘制的图片放在一个 sprite 上显示
这是代码
const width = 600;
const height = 600;
const color = Color.WHITE;
const data: Uint8Array = new Uint8Array(width * height * 4);
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
const index = i * width * 4 + j * 4;
data[index] = color.r;
data[index + 1] = color.g;
data[index + 2] = color.b;
data[index + 3] = color.a;
}
}
const image: ImageAsset = new ImageAsset();
image.reset({
_data: data,
_compressed: false,
width: width,
height: height,
format: Texture2D.PixelFormat.RGBA8888
});
const texture: Texture2D = new Texture2D();
texture.image = image;
const spriteFrame: SpriteFrame = new SpriteFrame();
spriteFrame.texture = texture;
spriteFrame.packable = false;
return spriteFrame;
这是运行效果

把代码 const height = 600; 改成 const height = 200;后 右边的图片全部丢失了

这是显示图片的 sprite




