00:00
00:00
Newgrounds Background Image Theme

mae6NG just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Dynamic Text Resize

327 Views | 3 Replies
New Topic Respond to this Topic

Dynamic Text Resize 2014-11-27 12:22:19


The more amount of text there is in the dynamic textbox, the smaller the text (so it fits inside).

How do I do that?

All the scripts I find are really long. Surely there's some short method which only has one or two lines of code?

Response to Dynamic Text Resize 2014-11-27 13:59:40


At 11/27/14 12:22 PM, Aprime wrote: The more amount of text there is in the dynamic textbox, the smaller the text (so it fits inside).

How do I do that?

All the scripts I find are really long. Surely there's some short method which only has one or two lines of code?

Do a while loop and shrink the font size until the textHeight is less than or equal to the textfield height.

Response to Dynamic Text Resize 2014-11-27 14:27:26


If you can work out some general relation between length of the text and the maximum allowed width of the text box - you can potentially omit a recursive solution.

However, aside from monospace fonts, the width and height of each character can vary enough for the general solution to break with certain strings. So you could apply the general solution first and then run a while loop to fine tune it or fix certain cases.

Response to Dynamic Text Resize 2014-11-28 06:58:13


Thanks!

var p:TextFormat =name_txt.getTextFormat();
while (name_txt.textHeight > name_txt.height) {
	p.size = int(p.size) - 1;
	name_txt.setTextFormat(p);	
}