2D Toolkit Forum

2D Toolkit => Support => Topic started by: rajmehta2509 on February 16, 2015, 01:23:43 pm

Title: Text Mesh
Post by: rajmehta2509 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.
Title: Re: Text Mesh
Post by: edb 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
Title: Re: Text Mesh
Post by: unikronsoftware 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.
Title: Re: Text Mesh
Post by: rajmehta2509 on February 20, 2015, 12:53:19 pm
That works like a charm thanks