Hello Guest

Poll

How to measure the height and width of text mesh in pixels.

How to measure the height and width of text mesh in pixels.
0 (0%)
How to measure the height and width of text mesh in pixels.
0 (0%)

Total Members Voted: 0

Author Topic: Text Mesh  (Read 3952 times)

rajmehta2509

  • Newbie
  • *
  • Posts: 3
    • View Profile
Text Mesh
« on: February 16, 2015, 01:23:43 pm »
I have been trying to make text notification in which i am using 2dtoolkit text and 2dtoolkit tiled sprite as background the problem is i need to scale my background according to the dimensions of the text but i could not find a way to calculate the height and width of the text.

edb

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Text Mesh
« Reply #1 on: February 16, 2015, 04:00:03 pm »
I'm using
Code: [Select]
myTk2dTextMesh.renderer.bounds.size.x // for width
myTk2dTextMesh.renderer.bounds.size.y // for height

Also can use
Code: [Select]
myTk2dTextMesh.GetMeshDimensionsForString(theString) // returns a Vector2 with dimensions

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Text Mesh
« Reply #2 on: February 16, 2015, 11:12:45 pm »
renderer.bounds.size returns the value in world space. you can convert that into pixels through the Camera.WorldToScreenPoint function but you probably don't need to do that - you can work out the buonds of the sprite and then scale it appropriately.

rajmehta2509

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Text Mesh
« Reply #3 on: February 20, 2015, 12:53:19 pm »
That works like a charm thanks