Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Highlight a word on touch
Started by cognibird Jan 23 2019 04:49 PM

8 replies to this topic

Best Answer Alan PlantPot , 25 January 2019 - 01:14 AM

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.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 12 posts
  • Corona SDK

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? 

 

 



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 447 posts
  • Corona SDK

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?



[TOPIC: post.html]
#3

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 12 posts
  • Corona SDK

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



[TOPIC: post.html]
#4

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 544 posts
  • Corona SDK

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.



[TOPIC: post.html]
#5

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 12 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 877 posts
  • Corona SDK

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.



[TOPIC: post.html]
#7

Alan PlantPot

[GLOBAL: userInfoPane.html]
Alan PlantPot
  • Contributor

  • 889 posts
  • Corona SDK

  Best Answer

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.


  • Appletreeman likes this

[TOPIC: post.html]
#8

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 12 posts
  • Corona SDK

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



[TOPIC: post.html]
#9

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 12 posts
  • Corona SDK

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. 




[topic_controls]
[/topic_controls]