Hello Guest

Author Topic: tk2dTextMesh pivot not correctly centered using Middle Center anchor  (Read 3549 times)

arkanoid87

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Hi,

I'm using 2D Toolkit v 2.3.3

I have the problem described in the attached screenshot. Basically the pivot of the generated tk2dTextMesh is not in the center if its bounding box. I've tried several options but the only solution I've found is to play with:

public static float GetYAnchorForHeight(float textHeight, GeomData geomData)
public static float GetXAnchorForWidth(float lineWidth, GeomData geomData)

in tk2dTextGeomGen. But it doesn't smell like a solution, at all.

May you help me in fixing this problem?

Thank you


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dTextMesh pivot not correctly centered using Middle Center anchor
« Reply #1 on: December 19, 2013, 11:48:10 pm »
The y centre of the text mesh won't correspond to the centre of the bounding box. For example it uses line height to calculate the center - this means that the center won't consider the vertical variation outside the line, e.g. the hanging part of the letter g, etc. the x axis uses the cursor position, i.e. the position the next char will appear at as the measure of width, which most often is larger than the actual character / mesh itself. Eg. a centred line of text should appear at the same position if it contains the string AAAAAA, or yyyyyyy and certainly if it contains AAyyAAyy.

If you want the mesh centre, you should just get that from renderer.bounds and adjust the position accordingly.