Jump to content

BitmapText Positioning


MattC
 Share

Recommended Posts

Hi,

I've been having difficulties understanding exactly how the positioning of BitmapText works. I'm trying to align text so it's bottom right corner is positioned at a particular point. I do this by setting the anchor to (1,1) and x/y appropriately.

However, when I try to do so, the text is always off by a few pixels. I'm having quite a difficult time figuring out exactly why.

Below is a code snip that renders text and a rectangle. My intention is to have the bottom right corner of both the text and rectangle be aligned. These are the results:

image.png.3a6d32346d726945d72aabc236f3eaf8.pngimage.png.3f19411c362bd5118910e14796f169d9.pngimage.png.277f237fe2ae6c6a0b1e135f11d4565a.png

I've tried everything I can think of to correct these small discrepancies. Probably something small and stupid I'm doing wrong, but really can't figure it out. Thanks. 

 

const app = new PIXI.Application({ width: 500, height: 500, backgroundColor: "white" });
document.body.appendChild(app.view);

PIXI.BitmapFont.from("font1", {
	fill: "black",
	fontSize: 30,
	stroke: "blue",
	strokeThickness: 3,
});

const x = 200;
const y = 200;

const text = new PIXI.BitmapText("FirstName123", { fontName: "font1" });
text.anchor.set(1, 1);
text.x = x;
text.y = y;

const rect = new PIXI.Graphics();
rect.beginFill(0xff0000);
rect.drawRect(0, 0, 150, 40);
rect.pivot.set(rect.width, rect.height);
rect.x = x;
rect.y = y;

app.stage.addChild(rect);
app.stage.addChild(text);

 

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

@jasonsturges Thanks for the reply! I'll look into fixing the stroke offset.

 

Still looking into why the right justification is off. It varies based on the characters used in whatever string is being rendered. Does not seem to be related to stroke width. 🤷‍♂️

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...