Best way to draw editable text

Hello,
I am using AdvancedDynamicTexture to create all word texts and link them with meshes. My problem now is that it starts to drop fps dramatically if I change the labels often.

Is there a better alternative to use for this use case:
I have around 50 players with each having two labels for the username and for the hitpoints. When players fight with each other, each hit on another player creates another label with the damage done for 1-2 seconds => and each player can attack around 5 times per second => 5 new labels to create.
I already tried to reuse the label instances but it seems that changing the text is the problem.

cc @DarraghBurke

1 Like

So, changing the text of a text block will force it to be re-drawn, which is a pretty expensive operation. One thing I can think of: you may want to try batching the text updates so that they all happen on a single frame. In other words, every 5 frames (or something), you can update all labels, instead of updating each label straight away. This may help reduce unnecessary re-draws.

Another thing you can try: if there is a fixed number of texts that you might render (say you need to render every integer from 1 to 50), you could paint them to an offscreen canvas first, then use drawImage to draw them where necessary into your scene. This will avoid the expensive text rendering operation, but it will require you to build your own rendering system rather than relying on Babylon GUI

Pinging @Deltakosh in case he knows any other tricks

2 Likes

Thanks, I will try it out.

EDIT:
I have benchmarked the sprite performance which is insanely fast (70k sprites until fps drops and I need only 2k sprites at max), I will go with your second approach: a spritesheet which contains the number 0-9 and draw them manually as needed and keeping static text like the username with the advanceddynamictexture.

1 Like

That’s awesome to hear!