2D Toolkit Forum
2D Toolkit => Support => Topic started by: awejk on February 18, 2013, 04:57:39 pm
-
(http://i.imgur.com/APweiiC.png)
// calculation width and height tooltip window
Vector2 dimension = textMesh.GetMeshDimensionsForString(text);
int countLine = Mathf.CeilToInt(dimension.x / textMesh.wordWrapWidth);
Debug.Log("countLine = " + countLine + ", dimension.x = " + dimension.x);
float heightY = Mathf.Abs(dimension.y) * countLine;
tk2dSlicedSprite slicedSprite = GetComponent<tk2dSlicedSprite>();
slicedSprite.dimensions = new Vector2(slicedSprite.dimensions.x, heightY);
why the number of lines does not correspond to the actual count?
Where did I wrong?
-
This is not correct way to count number of lines.
Word wrapping breaks the lines between the words, thus there are many "wasted" horizontal pixels left.
Have you tried to count number of '\n' characters in already formatted string?
-
I'll add some API functions for this in the next beta. Currently, you'll have to hack the FormatText to return the formatted string, from which you can count the number of newlines.
-
Thank you guys. Indeed the problem was '\n'. Replaced by formattedString and now works better.