微信开发者工具1.06.2405020 Stable
engine版本: 1.05.2204264
代码参考的官网 https://developers.weixin.qq.com/minigame/dev/game-engine/ui/erweiziyuantianjia.html
const canvasSp = this.entity.addComponent(engine.UISprite);
// 创建HTMLCanvas
const htmlCanvas = document.createElement('canvas');
htmlCanvas.width = 400;
htmlCanvas.height = 400;
const ctx = htmlCanvas.getContext('2d');
// 画个房子
ctx.fillStyle = '#fd0';
ctx.strokeStyle = '#0cc';
ctx.lineWidth = 10;
ctx.strokeRect(75, 140, 150, 110);
ctx.fillRect(130, 190, 40, 60);
ctx.beginPath();
ctx.moveTo(50, 140);
ctx.lineTo(150, 60);
ctx.lineTo(250, 140);
ctx.closePath();
ctx.stroke();
// 根据HTMLCanvas创建Texture2D
const texture2D = new engine.Texture2D();
texture2D.initWithCanvas(htmlCanvas);
// 根据Texure2D创建SpriteFrame
const spriteFrame = engine.SpriteFrame.createFromTexture(texture2D);
canvasSp.spriteFrame = spriteFrame;
然后提示报错 Failed to add component, detail: type="UISprite".