Auto-Adjusting Text Boxes

This forum is currently in read-only mode.
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • I don't know if someone has already supplied a tutorial to do this or if Construct has this feature already, but just in case they haven't, here is my way.

    You'll need three Private Variables for your Text Box.

    --------------------------------------------------------

    TextSize (this should be set to your chosen font size)

    NewWidth (this leave as 0)

    TextAmmount (this leave as 0)

    --------------------------------------------------------

    In a new event sheet create an Always event.

    Actions:

    Lives_Txt: Set 'TextAmmount' to len(Lives_Txt.Text)

    Start a new action. Select your text box, in this example mine is named Lives_Txt. Click Set Value. Your private variable should be TextAmmount and for your value click down on the System icon. When it comes up, look in the Text section for Get String Length, or just type lens(yada) Now the value you want to put inside the lens function is Lives_Txt.Text. You can type it in or click the Lives_Txt object and select Get Text.

    Lives_Text: Set 'NewWidth' to Lives_Txt.Value('TextSize')*Lives_Text.Value('TextAmmount')

    This should be obvious if you're used to tooling around in the events already. You start your

    action with the Lives_Txt object (or whatever you've called it) and set the value of NewWidth to the size of your font (represented here as TextSize)multiplied by the size of your string.

    Lives_Txt: Set width Lives_Txt.Value('NewWidth')+5

    Start your action and in the Size & Positions section theres a Set Width command. What we're doing is inserting the value of NewWidth that we just found, into the Set Width command. Then I tacked on a +5 to add some room for things like bold, italics, the differing widths of letters.

    That should be it, other than having to do this for each Text object you want the size to update. Let me know if someone has a better way of doing this or if you found this tutorial to be unclear.

  • I might be missing something, but why not just make it long to begin with if all you are doing is adjusting the width?

  • nice. If you could post an example .cap it would be even nicer.

  • This was useful where I needed to add text with a border; dynamic text widths allow you to make things look smarter.

  • The purpose is for Dialog boxes in RPGs or something similar. Here's the cap, http://www.box.net/shared/flbrtsc86h I hope it helps.

    Theres a few additions, now instead of the text possibly going off screen if its too long, the box will drop down a little bit.

    It simply checks if the NewWidth would be wider than a predetermined length (like the size of a background image to put behind your dialog box.) If so it drops down. Then if it is twice as much as that length, but not 3 times as much, it will drop down a second level. And if its three times as long, it will drop down a third level.

    I set it up to also adjust the height of the background images, and theres a private variable for those called OrigHeight. You set that as the starting Height of your image (in the panel on the left, no need to do it in an event.) So when the Text box is adjusting its height, the image will set its height to the OrigHeight + an amount depending on how many levels the text has to adjust.

    Theres a seperate event sheet to control the actual dialog, its not a very good example and theres a few kinks but I just hacked it up tonight for this demo.

  • This combined with the panel object can make for sweet, sweet RPG dialog.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • By panel object, do you mean just the background image like I used in that cap, or a feature of Construct I haven't found yet?

  • The Panel object is a new feature of version 0.99.4

  • Currently working on an update for this, so far I have the panels in place and working, most of a new button system to look more like a console RPG and am revising the dialog section to make it into a system so you can build and call up scripts easily. (scripts in the movie sense of the word)

    I'm going to leave the old link up for those who haven't switched to 9.4 but will post a new one when the dialog system is finished.

  • http://www.box.net/shared/8zb2lnnsca

    edit: I should mention its made in 99.42 so won't work with earlier versions (earlier than 99.4 probably)

    Thats the new cap, the change from tiled backgrounds to panels was a simple replacement but I also added a generic dialog system that can be changed for things like letting an NPC ask a player to go on a quest.

    Its pretty heavily commented, its not really a tutorial. I'm going to write that in a few days.

    I'm not sure how much better this system is actually, it loads values into hash tables from an INI file, so that you get the ease of update from using a .txt as the INI file.

    Later on I'll update it even more with some preprogrammed responses for the player to choose from like in a console RPG.

    Ya'll let me know what you think, are the hash tables better than just getting it straight from the INI all the time or does it even out? I know INIs are supposedly slow, but what about hashes?

    this isn't the finished project, but I'd really like some advice before I continue

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