How properly use the text metrics?

Hello!

How do I properly use getTextMetrics()?

Being more specific: Do I need to create a metric for EACH size of the font that I will be using?

You don’t have to create text metrics yourself, but if you are, then yes.

I was having issues with performance before using metrics. Now I create a text and get its metrics to use as a base. For example:

verdanaText = this.add.text(0, 0, "metrics", {fontFamily: 'Verdana', fontSize:'30pt'});
metricsVerdana = verdanaText.getTextMetrics();

Then I would use the metricsVerdana in all other Verdana texts. But I don’t know if I need a metric for each font size. Or I’m doing everything wrong?

You need a metric for each font-family–font-size.

2 Likes