Wednesday, July 20, 2022
HomeGame DevelopmentWill canvas options work in native construct? - Cocos Creator

Will canvas options work in native construct? – Cocos Creator


Hello all, I’m producing textures with Canvas Html aspect and put to Cocos Creator Sprites, however I’m questioning if such code will work on native?

        const canvas = doc.createElement("canvas");
        const ctx = canvas.getContext("second");

        const picture = this.spriteFrame.texture.picture.information;

        console.log(picture);

        canvas.width = picture.width;
        canvas.top = picture.top;

        ctx.drawImage(picture, 0, 0);
        ctx.restore();
        const imageData1 = ctx.getImageData(
            0,
            0,
            drawPatterns.rect.width,
            drawPatterns.rect.top
        );

        ctx.putImageData(imageData1, 0, 0);

        let pixelsArr: ArrayBufferView = imageData1.information;
        let imageAsset: ImageAsset = new ImageAsset();
        imageAsset.reset({
            _data: pixelsArr,
            width: 100,
            top: 100,
            format: Texture2D.PixelFormat.RGBA8888,
            _compressed: false,
        });

        let tex: Texture2D = new Texture2D();
        tex.picture = imageAsset;
        let spriteFrame = new SpriteFrame();
        spriteFrame.texture = tex;
        spriteFrame.packable = false;


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments