I am currently utilizing the threejs editor as a foundation for my threejs projects. One issue I am facing involves displaying tooltips when the user hovers over specific elements. To accomplish this, I have set up a canvas that is rendered as a texture on a sprite.
// Creating a canvas element
var canvas1 = document.createElement('canvas');
var context1 = canvas1.getContext('2d');
context1.font = "Bold 20px Arial";
context1.fillStyle = "rgba(0,0,0,0.95)";
context1.fillText('Hello, world!', 0, 20);
// The canvas content will be used for a texture
var texture1 = new THREE.Texture(canvas1)
texture1.needsUpdate = true;
// Using the texture as a material
var spriteMaterial = new THREE.SpriteMaterial({
map: texture1,
useScreenCoordinates: false
});
// Creating the sprite and adding it to the scene
var sprite1 = new THREE.Sprite(spriteMaterial);
sprite1.scale.set(1000, 500, 1.0);
sprite1.position.set(50, 50, 0);
scene.add(sprite1);
var i = 0;
// Changing the content of the canvas
setInterval(function () {
context1.clearRect(0, 0, canvas1.width, canvas1.height);
var message = 'test' + i++;
context1.fillText(message, 4, 20);
texture1.needsUpdate = true;
}, 1000)
The text "test0" appears, but the sprite does not update. How can I go about updating the text on the sprite? Is there something missing in terms of cache invalidation?