2D Toolkit Forum

2D Toolkit => Support => Topic started by: arkanoid87 on December 19, 2013, 04:53:12 pm

Title: tk2dTextMesh pivot not correctly centered using Middle Center anchor
Post by: arkanoid87 on December 19, 2013, 04:53:12 pm
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

Title: Re: tk2dTextMesh pivot not correctly centered using Middle Center anchor
Post by: unikronsoftware 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.