Hello Guest

Author Topic: Rendered size of tk2dTextMesh  (Read 4856 times)

mheydlauf

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Rendered size of tk2dTextMesh
« on: January 08, 2014, 05:48:59 am »
Hi,

I'm trying to create a background for a tk2dTextMesh in my 2d side scroller.  The text of the tk2dTextMesh is set dynamically (it's read from a data file which represents a level in my game).  The tk2dTextMesh is used to show informational messages to the user like "Press spacebar to jump".  Within the game these messages are rendered as sort of street signs or graffiti that are part of the background.

So my question is, how would I scale my sign background so that it fits the bounds of the text?

Any pointers are greatly appreciated.

Many thanks,
Mike.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Rendered size of tk2dTextMesh
« Reply #1 on: January 08, 2014, 11:49:19 am »
You can get the bounds of the text mesh by textMesh.GetEstimatedMeshBoundsForString before you set it.
If you need it after you set it, you can do so very efficiently by textMesh.renderer.bounds

With that you can scale your sliced sprite by setting dimensions, or scale your sprite, etc. Lots of options.

mheydlauf

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Rendered size of tk2dTextMesh
« Reply #2 on: January 08, 2014, 04:02:15 pm »
Hmmm, I had tried textMesh.renderer.bounds.size after setting the text but it always returned the same size regardless of what text I used.  I'll try GetEstimatedMeshBoundsForString instead and see if I have better luck.

Many thanks for the support.

Mike.

Edit: GetEstimatedMeshBoundsForString did the trick, thanks!
« Last Edit: January 08, 2014, 09:29:26 pm by mheydlauf »