Autofit text inside the text object (NOT the textbox obj)

0 favourites
  • 7 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • Hi community and Ashley

    I am loading and importing text through an xml and into a text object. Some of the loaded words are short and some are very long.

    On runtime, HOW can i make the text change its font size in order to fit into the text box without getting cut off?

    Thanks in advanced for the help...

  • I don't think you can determine with events if text fits the text box or it's too long. I had simillar problem with my quiz game. I use Sprite Fonts in my game, but the solution can be pretty the same with Text object. I manipulate the Sprite Font scale based on the text lenght. But I had to test it manually several times to find out the correct resizing ratio based on the text lenght. So you cannot check if text lenght is ok for your text box, but you can predict the resize you have to do on the fly.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't know that you can autofit the text using font size changes, but you can definitely fit the text object to the text using events.

    You could try a hack solution, like:

    Do while: Compare Text.TextWidth to Text.Width

    and set font size: Text.FaceSize - 1

    Until it fits.

  • gumshoe2029, it seems that your method may work. I tried it but it is not working as it should. Would you be able to share a brief CAPX with those events to see how you are applying it.

    If you can, i Will give you major credit for figuring this out for the community.

  • It was just that, an idea. I have never gotten it working myself, lol.

    You will want to put a wait in there though. The asynchronicity of JavaScript is such that it will break without a short (like 0.05-0.1s) wait in the loop.

  • Yea I think gumshoe has mentioned one of the most likely solutions to the problem. If I had time I would throw together an example but I'm at work so if you haven't gotten it working by tonight I can try it out.

  • , i would highly appreciate that!

    Will wait on your example then.

    Many thanks.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)