How do I track the position of a letter in a text?

From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hello,

    I would like to make a typewriting game where when you write a letter from the keyboard, an animation would appear (like a hand that writes the letter down).

    Do you know how can I track the position of each letter and update that position when the user presses another key?

    Scenario:

    1. the user type 'w' - an animation will occur at the position of 'w'

    2. the user type 'o' - an animation will occur at the position of 'o'

    3. the user type 'w' - an animation will occur at the position of 'w'

    In the game, you will be able to hit Enter and make a newline or hit Backspace and delete some letters. I would like to use the 'Text' object from Construct 3. Or, if it is not possible, I would like 'Text Input'.

    So.. anybody has done something like this? Or know how to track the position of the letters?

    Thank you! :)

  • Look at the 'tokenat' expression, it is used for this where you track individual characters in a string.

  • Look at the 'tokenat' expression, it is used for this where you track individual characters in a string.

    Hello,

    I tried with that, but I couldn't find how to get a position of the last letter.

  • Oh do you mean the actual position on screen as in the co-ordinates of the letter, I don't know how to do that or if it's possible.

  • Oh do you mean the actual position on screen as in the co-ordinates of the letter, I don't know how to do that or if it's possible.

    Yes.. that was what I wanted to achieve...

    I understand - thank you for trying to help me with this! :)

  • if you use a monospace font or a sprite font, you can do some calculations

    https://drive.google.com/file/d/1ZKe6oDW63TadkGy-U6c1Y8S-CkHtHF1G/view?usp=sharing

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • if you use a monospace font or a sprite font, you can do some calculations

    https://drive.google.com/file/d/1ZKe6oDW63TadkGy-U6c1Y8S-CkHtHF1G/view?usp=sharing

    Hi mrcgkh,

    This is how I made it in the end.

    I don't use a monospace/sprite font, but it worked to set the X position of the effect to "Self.X + random(30,50)" once the player will write a letter.

    So, when a player write "a", but "cursor" will move from initial X to "Self.X + random(30,50)". To control the line in the text, I put a maxim of 12 characters on the line and calculate where the Y of the line will be, so, when the "cursor" reach the line limit (12 characters), to the text I will append a newline and the cursor position will go to X=first_letter and Y=second_line.

    It is not 100% perfect, but it works.

    Have a great day! :)

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