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 factor 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("2nd");

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

        console.log(picture);

        canvas.width = picture.width;
        canvas.peak = picture.peak;

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

        ctx.putImageData(imageData1, 0, 0);

        let pixelsArr: ArrayBufferView = imageData1.knowledge;
        let imageAsset: ImageAsset = new ImageAsset();
        imageAsset.reset({
            _data: pixelsArr,
            width: 100,
            peak: 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;


attempt to construct to android or ios, then you’ll realize it.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments