Text width property is inaccurate
opened this issue · comments
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) //inaccurate
g.canvas.ctx.font = testText.font
testText.width = g.canvas.ctx.measureText(testText.content).width
console.log(testText.width) //now accurate