碰到一个代码绘制图片的问题

需要自己绘制一张纯色的图片,目前测试是把这张绘制的图片放在一个 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;

这是运行效果
微信图片_20220218131957

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

这是显示图片的 sprite

修改下这里试试:

确实可以,但是我想实现这样的效果
1645170086(1)
你的代码我不知道咋去修改 :open_mouth:

没实现,有点问题,大佬求救 :tired_face:

好像又可以了,哈哈哈谢谢大佬

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。