excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.82k stars 188 forks source link

SpriteFont is not aligned #2152

Closed lampewebdev closed 2 years ago

lampewebdev commented 2 years ago

Steps to Reproduce

Font should be aligned on the X axis

Actual Result

Fonts are not aligned

Screenshot 2021-12-08 at 09 07 56

Environment

Current Workaround

None

eonarheim commented 2 years ago

@lampewebdev Thanks for the excellent bug report!

Definitely not working as expected.

It appears that there is some internal state being shared across in the ex.SpriteFont that causes the placement to be buggy when re-used in other ex.Text objects. As a workaround while we work the bug, cloning the spriteFont seems to work for now (although not ideal).

image
var textA = new ex.Text({
  font: spriteFont.clone(),
  text: "1"
});
var textAA = new ex.Actor({
  anchor: ex.Vector.Zero,
  x: 100,
  y: 10,
  z: 1,
});
textAA.graphics.add(textA);
game.add(textAA);

var textB = new ex.Text({
  font: spriteFont.clone(),
  text: "22"
});
var textBA = new ex.Actor({
  anchor: ex.Vector.Zero,
  x: 100,
  y: 30,
  z: 2,
});
textBA.graphics.add(textB);
game.add(textBA);