How do I changes the size of text box according to the number of characters and lines in it?

0 favourites
  • 5 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • hi hi!!

    I'm building a game that displays a lot of text boxes.

    How can I make it so that when I create the text boxes, the system detects how many characters are in the text box, changes the size of the text box according to the number of characters and lines there are, and creates a background for the box in a size that matches the created text box?

    I create a text cube and in it is written:

    "HELLO

    BOB"

    I want to create something that will check what is in a text box:

    1- How many lines are there? (2 In our case)

    2- What is the length of the line that has the most characters (in our case, line 1, which has 5 characters compared to line 2, which only has 3 characters)

    Now that I have this information I want the text cube to change its dimensions to the size of the row that has the most characters, and to the height that contains the number of rows.

    After that I want and creates a background for the box in a size that matches the new size of text box

    how do I do it?

    Here's an example of what I'm trying to achieve (pictures taken from a game called Lil' Guardsman)

    I thank you from the bottom of my heart

    Tagged:

  • I know you asked about the information for text length and lines etc. but I don't think you need it for this purpose. It's actually much easier!

    You can simply use the Text object properties TextWidth and TextHeight.

    Then set a 9-patch object (probably the best solution for this) behind the text, and set its size to Text.TextWidth, Text.TextHeight. This will be very tight, so you can add some extra border.

  • It is so amazing!

    But it creates perfect square cubes - what if I want to create a nicer background some sprite with rounded edges that looks better?

    For me to find out the size so that I can create a sprite that I will place in the background of the text

    Anyway this is great progress for me thank you very much!

    I just need to understand how I can know the information I need to put in the background of the text cubes background like in the examples I gave

    thanks again

  • I'm not sure I understand correctly, but that's exactly what the 9patch is for. Technically it's even better than a sprite.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/9-patch

    You can absolutely give it rounded corners and whatever design you like. It's perfect for recreating the exact same look of your example.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I didn't know that until now - thank you very much! I will definitely use it! I really appreciate your help ^__^

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