Hello Guest

Author Topic: Need help with Word Wrap in text mesh  (Read 4938 times)

Koosmono

  • Newbie
  • *
  • Posts: 3
    • View Profile
Need help with Word Wrap in text mesh
« on: January 19, 2013, 05:16:10 am »
I'm having trouble getting the word wrap width option to work correctly. When I adjust the properties this way and look in the editor while the game is running, the proper number appears in the word wrap field and the formatting box is checked. Am I not  understanding something correctly? My thinking was that the width was a number of characters the string would display before moving to a new line where it would repeat that process.

I am looking to have the text appear on multiple lines and so far I can't find anyway to do so in code.

Thank you for any help. It will be very much appreciated.

Code: [Select]
public void Awake()
{
textMesh = GetComponent<tk2dTextMesh>();

textMesh.formatting = true;

textMesh.wordWrapWidth = 15;

textMesh.Commit();

textIndex = 0;

_TypedStates = typedStates.waitingToBeTyped;
}

public void UpdateText(float GameTime)
{
if(_TypedStates == typedStates.Typing)
{
if(GameTime > lastUpdateTime + textTypeSpeed)
{
textMesh.text = fullString.Substring(0, textIndex);

lastUpdateTime = GameTime;

textMesh.Commit();

if(textIndex >= fullString.Length)
_TypedStates = typedStates.FinishedTyping;
else
textIndex++;
}
}
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Need help with Word Wrap in text mesh
« Reply #1 on: January 19, 2013, 04:00:08 pm »
The width isn't the number of characters on a line - that wouldn't work with normal variable-spaced fonts, as the size of each character will vary.

The width parameter refers to the texture space width for the font. If your font is being displayed pixel perfect, it means the width is the number of pixels the where the line is wrapped at. The easiest way to size this is to physically move the widget in the interface. Otherwise, you will need to calculate the pixels you want to wrap at and enter that.