Highlight a word on touch

I would like to highlight a word on touch, like this:

153o7e9.png

I managed to do it with spritekit/swift by splitting the words from a string into an array and then adding them to labels with a spritenode behind it. So when I tap on it it changes the color.

I would really like to know if there is a better way of doing this here? 

Hi cognibird.  How much text are we talking about?  Will the exact text been know in advance or will there be dynamic and unpredictable text arrangements?

Hi sporkfin. We are talking about a lot of text, on some levels multiple pages long. It will be known in advance.

If I’m not mistaken, Corona’s newText simply takes a string and turns it into a display object. So the only way to create something like that would be the long way around, i.e. splitting a string into words and turning each word into a separate newText object with a touch event listener.

Well, I guess I have to use the same approach. Thanks XeduR for the reply. If someone else has a better idea please let me know.

I’ve been dabbling with stuff like this a well. The only way to do it is splitting your string into different words and adding a rectangle for each word as well.

I’ve used this recently which lets you render an HTML file in Corona:  

https://github.com/mimetic/corona-textrender

You can designate words as hyperlinks in the HTML data, and this library has a listener for handling hyperlink click behaviour (so you can change text colour on click instead of trying to open a url).

It also lets you have bold and italic text within a line of text, rather than forcing you to pick the font type before rendering the entire piece of text.

This looks great, thank you Alan! I will try it out.

This is a great answer to my question and it does what I’ve asked for. I just didn’t mention some other things that I don’t think this renderer can do. Like selecting the word and then changing the color with an external object/ button and also I wanted to make a small animation maybe with the text when tapped.  

Thank you for the answer though, I will use it for some other things. 

Hi cognibird.  How much text are we talking about?  Will the exact text been know in advance or will there be dynamic and unpredictable text arrangements?

Hi sporkfin. We are talking about a lot of text, on some levels multiple pages long. It will be known in advance.

If I’m not mistaken, Corona’s newText simply takes a string and turns it into a display object. So the only way to create something like that would be the long way around, i.e. splitting a string into words and turning each word into a separate newText object with a touch event listener.

Well, I guess I have to use the same approach. Thanks XeduR for the reply. If someone else has a better idea please let me know.

I’ve been dabbling with stuff like this a well. The only way to do it is splitting your string into different words and adding a rectangle for each word as well.

I’ve used this recently which lets you render an HTML file in Corona:  

https://github.com/mimetic/corona-textrender

You can designate words as hyperlinks in the HTML data, and this library has a listener for handling hyperlink click behaviour (so you can change text colour on click instead of trying to open a url).

It also lets you have bold and italic text within a line of text, rather than forcing you to pick the font type before rendering the entire piece of text.

This looks great, thank you Alan! I will try it out.

This is a great answer to my question and it does what I’ve asked for. I just didn’t mention some other things that I don’t think this renderer can do. Like selecting the word and then changing the color with an external object/ button and also I wanted to make a small animation maybe with the text when tapped.  

Thank you for the answer though, I will use it for some other things.