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

Get help using Construct 2

Post » Tue Sep 01, 2015 7:35 am

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...
B
107
S
20
G
8
Posts: 155
Reputation: 11,752

Post » Tue Sep 01, 2015 10:16 am

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.
ImageImageImage
B
31
S
19
G
82
Posts: 1,038
Reputation: 46,205

Post » Tue Sep 01, 2015 10:19 pm

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.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Wed Sep 02, 2015 9:19 pm

@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.
B
107
S
20
G
8
Posts: 155
Reputation: 11,752

Post » Thu Sep 03, 2015 5:23 pm

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.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Thu Sep 03, 2015 5:29 pm

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.
Twitter: https://twitter.com/pudgyplatypus

Learn to make a clicker game for cheap!
https://www.scirra.com/store/games-with ... e-game-666

Try out Pixel Golf on the Scirra Arcade!
https://www.scirra.com/arcade/sports-ga ... el-golf-67

Pudgy Platypus Games website!
www.pudgyplatypus.com
B
59
S
20
G
5
Posts: 212
Reputation: 7,390

Post » Thu Sep 03, 2015 5:59 pm

@Djfuzion, i would highly appreciate that!

Will wait on your example then.

Many thanks.
B
107
S
20
G
8
Posts: 155
Reputation: 11,752


Return to How do I....?

Who is online

Users browsing this forum: draiza and 12 guests