Hi all. I am trying to create own drawn texture from canvas I created and setup it to the sprite component, but examples I frond look like impossible on Cocos Creator 3.
For example I can’t find " initWithElement" method in Texture2D class.
Can anyone please provide me an example how to create sprite frame from canvas element?
My current code is:
const spriteHolder = this.spriteHolder = this.addComponent(Sprite);
const canvas = this.canvas = document.createElement('canvas');
canvas.height = 100;
canvas.width = 100;
const ctx2d = this.canvas.getContext('2d');;
ctx2d.fillStyle = '#ff0000';
ctx2d.fillRect(0, 0, 100, 100);
const texture = this.texture = new Texture2D();
texture.uploadData(canvas);
spriteHolder.spriteFrame = new SpriteFrame();
spriteHolder.spriteFrame.texture = texture;
spriteHolder.spriteFrame.rect = new math.Rect(0, 0, 100, 100);