【发布时间】:2021-12-31 03:19:15
【问题描述】:
我试图在我的框架项目中使用画布作为纹理。我找到了一些说明here。它提到:
纹理会随着画布的变化而自动刷新。
但是,我今天试了一下,画布只能在 init 函数中更改/更新。之后无法反映对画布的更新。这是我的实现:
module.exports = {
'canvas_component': {
schema: {
canvasId: { type: 'string' }
},
init: function () {
this.canvas = document.getElementById(this.data.canvasId);
this.ctx = this.canvas.getContext('2d');
this.ctx.fillStyle = "#FF0000";
this.ctx.fillRect(20, 20, 150, 100);
setTimeout(() => {
this.ctx.fillStyle = "#FFFF00";
this.ctx.fillRect(20, 20, 150, 100);
}, 2000);
}
}
纹理的颜色变化从未改变。有什么我错过的吗?非常感谢您的任何建议。
【问题讨论】:
标签: javascript canvas aframe