threedollarbill

BitmapText align "center" does not align properly

Recommended Posts

I am experiencing an odd problem aligning the text of a BitmapText to the center.

I am successfully able to wrap the text by using the "maxWidth" property, but the alignment of the text is uneven / jagged (see attached screenshot).

It doesn't align to the center, some words are more to the left, and some are more to the right. I can't understand what's going on.

I am using the code below (typescript):

let hintText:Phaser.BitmapText = this.game.make.bitmapText(0, 100, "MSR", "", 25, "center");
hintText.maxWidth = 310;
this.add(hintText);
hintText.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut mattis velit. Cras placerat fermentum dictum. Donec at semper enim. Donec euismod pulvinar volutpat."

 

ss.png

Share this post


Link to post
Share on other sites

The 'align' argument is for the alignment of multi-line text, it doesn't do anything if there is only one line of text. In your example, there is only one line of text, because there are no new-line characters anywhere in it.

maxWidth doesn't add in newline characters, which is why 'align' is unable to do anything in this case.

Personally I think the outcome is, rightly, unexpected though. You'd want it to do what you expect above, however the code to handle that isn't in the class file. PR anyone?

Share this post


Link to post
Share on other sites

Oh I see. Thanks for that Rich. :) Yeah, it seems there's currently no easy way to achieve that "centered" effect huh? Unless I manually add new lines.. I am starting to look at using Phaser.Text instead, maybe that one has more options for wrapping, etc. This is my first time using Phaser btw. I come from the Flash world.

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

  • Recently Browsing   0 members

    No registered users viewing this page.