Sign in to follow this  

Method to fit text within a box

Recommended Posts



I've got a variable text string, what's the best method to fit it within a fixed size box ?


I'm thinking of a loop to update fontsize and get the width/height until the text fit.





Share this post

Link to post
Share on other sites

It really depends on the use case.

If the text changes often, you might want to extend the Text prototype and loop over ctx.measureText(..).width instead of drawing the text until you find a fitting size.

Since the box also has a height, I would wrap at box.width and loop until the height fits into the box.

(Not sure if the current version of phaser i using a pixi version with fixed wordwrap issue)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.