Looking for a better way to update DynamicTexture

Hi,

In my project there are many objects which have an (x,y,z) with transparent background text above each of them (Plane.material.dynamicTexture.drawText(x,y,z))
Now, I wanted to animate the objects and I made the dynamicTexture change each frame based on the new coordinates of the objects by disposing the current dynamicTexture and creating a new one.
Well this process drops the fps down to about 5.
Anyone has abetter method for updating the text? or other way to show this text?

Thanks

You don’t have to dispose the texture, you can just call drawText again on it

@Gijs If I do this I see the previous texts behind, notice I said the textures are transparent

You can clear the canvas like this:

let size = texture.getSize();
let ctx = texture.getContext();
ctx.clearRect(0, 0, size.width, size.height);
1 Like

@Gijs Can you show me how to use this?

https://www.babylonjs-playground.com/#5ZCGRM#247

I tried here but it doesn’t do anything

Of course; it’s because the texture hasn’t been .update()d, but the drawText function does that for you by default (last parameter):

https://www.babylonjs-playground.com/#5ZCGRM#249

@Gijs Amazing! Thank you!

1 Like