Hello Guest

Author Topic: Using wordWrapWidth in code  (Read 4027 times)

edb

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 43
    • View Profile
Using wordWrapWidth in code
« on: February 24, 2015, 08:39:53 pm »
I need to make a textmesh's wordWrapWidth change depending on the width of something else.

I saw this from another post:

"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."

I guess I'm needing help with where I need to "calculate the pixels you want to wrap at".  I know the world, screen and viewpoints of where I want to wrap at, but I don't know how to get those points in terms of the wordWrapWidth.

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using wordWrapWidth in code
« Reply #1 on: February 25, 2015, 09:49:28 am »
What is the relationship between your textmesh / font and the screen size? If you can work that out you will be able to work this out directly. Eg. if its pixel perfect, the size will be screen size. If you're using tk2dCamera and the font is pixel perfect to the native resolution, it will be in native resolution units.

You can also use the fontData texelSize (world units) and the localScale / textMesh.scale of the textmesh itself to work out an exact size.

edb

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Using wordWrapWidth in code
« Reply #2 on: February 26, 2015, 12:24:48 am »
Thanks for the reply.  I ended up using the native resolution.

For anybody else reading this - I'm making a mobile game and using native resolution width for landscape and native resolution width * aspectRatio for portrait.