You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that when creating a text sprite, the width property returned is inaccurate. This makes positioning text difficult. I think it's something to do with the font having to be set on the canvas context before measureText is called. The following code seems to fix the issue.
testText=g.text("HELLO, WORLD!","75px Verdana","orange")console.log(testText.width)//inaccurateg.canvas.ctx.font=testText.fonttestText.width=g.canvas.ctx.measureText(testText.content).widthconsole.log(testText.width)//now accurate
The text was updated successfully, but these errors were encountered:
I've noticed that when creating a text sprite, the width property returned is inaccurate. This makes positioning text difficult. I think it's something to do with the font having to be set on the canvas context before measureText is called. The following code seems to fix the issue.
The text was updated successfully, but these errors were encountered: