Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text width property is inaccurate #70

Open
ghost opened this issue Feb 9, 2018 · 0 comments
Open

Text width property is inaccurate #70

ghost opened this issue Feb 9, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 9, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants