Jump to content

How to center a bitmapText


totallybueno
 Share

Recommended Posts

Hi there guys,

I´m having a problem with align and bitmapText... and it seems that it´s not working (at least not for me)

 

I guess this should be enough:

this.marker= this.game.add.bitmapText(posX, posY, 'bloodyFont',"0", 85);this.marker.align = "right";

But if I change "right" for "center" or "left", the result is exactly the same, nothing changes. At least I tried the angle property and it´s working perfectly, but align is not... do I need something else? Am I doing something wrong?

 

Anyway, as I can´t get the width, I can´t do it "manually", so what should I do?

 

Thanks in advance.

Link to comment
Share on other sites

The alignment only works when the text is multi-line. It's not entirely intuitive that this is the case, but it is. If you need to align a single line of text I'm afraid you'll need to manually adjust its position every time you update it.

this.marker.text = "Blah";this.marker.updateText(); // this is important to calculate the textWidth straight away rather than waiting until the next updatethis.marker.x = posX - this.marker.textWidth;

Or if you want it centered:

this.marker.x = posX - (this.marker.textWidth * 0.5);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...