Jump to content

Text width issues


SimonW
 Share

Recommended Posts

I'm trying to add labels to polygons, and I was hoping I would be able to limit the label to the size of the polygon by setting label.width to polygon.getBounds().width. Unfortunately that doesn't seem to work. Setting the text width is certainly doing something, but it isn't setting it to the width of the polygon.

Example here:
https://jsfiddle.net/yvk256L1/5/

As you can see, making the string longer doesn't change anything. Different fonts give different widths. The scale does seem to be proportional to the width of the rectangle at least.

Link to comment
Share on other sites

Yeah, right. Its a pixi bug. Need to update width first, then to assign it )

SOLUTION:

rect1.addChild(centerLabel1);
centerLabel1.anchor = new PIXI.Point(0.5, 0.5);

console.log(centerLabel1.width); // WAY 1 - THIS IS UPDATING centerLabel1.width
centerLabel1.updateText(); // WAY 2 - THIS IS UPDATING IT TOO

centerLabel1.width = bounds1.width;
centerLabel1.scale.y = centerLabel1.scale.x;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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