How do I jump to position of a specific word in a text object?

  • Hi. I want to add a full text search to my app and added the text object contents to an array to search it. Highlighting the searched world should be no big problem with find and replacing/adding some BB Code, right?

    But there is no way to get the coords of a word inside a text object to jump/scroll to it?

  • Do you mean screen coordinates (x,y), or position (index) of a word in text?

    Text is rendered differently, so it's a really difficult task to get correct screen coordinates with text object. You can do it with sprite font though.

    If you just need to know the position of a sub-string, use find() expression. For example, find("ab cd ef", "cd") will return 3.

  • I meant the coords to scroll to it.

    But how can you get the x and y of a found word in a sprite font object?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In sprite font you can get the size of each character, space width, line height etc. This allows you to calculate position of any words in the text, but in a big multi-line text with word wrapping it may not be a very easy task.

    How do you currently scroll the text? Do you have a really tall text object and scroll the entire layout?

  • Thanks. Its not implemented yet, just thinking about how to do it.

    In general a layout has multiple text objects and if you search it should jump to the first found word on the layout. Or show a result popup with buttons to jump to next/prev like most browsers have.

    But if it's so complicated I may skip the jump-to part and just implement full text search to find the layout where the word is on and jump to the layout. Marking words should be not so hard.

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