2 Small Questions: Certain Text Effects & Inserting Strings.

Hi folks,
            I’ve 2 small questions, basically I’m wondering if these are possible.
 
1.)
I have a NewText:

 local nameText = display.newText("Hi, I'm Matthew it's nice to meet you.",     400, 200, native.systemFontBold, 24);

So I know I can use setTextColor() to colour the text a certain Colour but I was wondering if it’s possible to Colour or Bold only one word in a string?

You see I’d like to ‘highlight’ certain words, be it bold or colour change?
Something like: “Hi, I’m  Matthew  it’s nice to meet you.” (without the spaces in the [B]  of course.)
 

2.)

The second question is whether it’s possible to add in a string after an integer.
What I’m trying to do is tell you how many seconds you have, something like:

‘20s’

So if my variable tells me it’s 20, I need to add an ‘s’ at the end.

local timeText = display.newText(Data[1].timeCost, 200, 200, native.systemFontBold, 22)

My string pulls out an integer from a table… 20.
I can’t find a way I can somehow add ‘s’ to the end of whatever it pulls out.
Something like:
…newText(Data[1].timeCost,_ “s” _, 200…)

Thankyou in advance :slight_smile:
                                       Matt. x

 

  1. With display.newText() you cannot change the properties of just part of the string.  It’s all or nothing.  You can simulate it by using separate strings, but…

2.  Yes and no.  You can do something like:

[lua]

    count = count + 1

    if count ~= 1 then

          somedisplaytext.text = count … “s”

    else

          somedisplaytext.text = count

    end

[/lua]

In this case, count stays a number and it’s converted to a string when you concatenate the “s” to the end and your sticking it somewhere where text is expected.

This won’t work:

[lua]

    count = count + 1 … “s”

[/lua]

because you can’t do math with a string.

Thanks for the reply.

It’s a shame about the inability to highlight certain words in a string. It would have helped draw peoples attention to meaningful words in a sentence.

As for 2.) 

.. "s"

That’s exactly what I needed, I had already called it in the correct fashion, from a table so slapping that at the end worked a charm! :slight_smile:

I’ve never worked with ’ … ’ before what does that mean to lua?

Even though I have long times like 1047s now haha, it’s great. Optimally I’ll add some code to turn that into the appropriate 17m 45s

But I’ll get to that later on.

Much appreciated

If you need to do styled text, you can use a webView, then you can do HTML and CSS to your hearts content to style text.  For many cases, a screen might have fixed text and I can make it look better in Photoshop than I can with straight up fonts.  LIke in my game OmniBlaster, I just did a Photoshop PSD file  that has all my credit text in it on the background.  Save out the one file then in my code, it’s just the background image and I don’t have to adjust any code.  If I change the credits, I just have to drop a new image file in my images folder.

I know for business apps or dynamic text, this isn’t the best of worlds.

  1. With display.newText() you cannot change the properties of just part of the string.  It’s all or nothing.  You can simulate it by using separate strings, but…

2.  Yes and no.  You can do something like:

[lua]

    count = count + 1

    if count ~= 1 then

          somedisplaytext.text = count … “s”

    else

          somedisplaytext.text = count

    end

[/lua]

In this case, count stays a number and it’s converted to a string when you concatenate the “s” to the end and your sticking it somewhere where text is expected.

This won’t work:

[lua]

    count = count + 1 … “s”

[/lua]

because you can’t do math with a string.

1 Like

Thanks for the reply.

It’s a shame about the inability to highlight certain words in a string. It would have helped draw peoples attention to meaningful words in a sentence.

As for 2.) 

.. "s"

That’s exactly what I needed, I had already called it in the correct fashion, from a table so slapping that at the end worked a charm! :slight_smile:

I’ve never worked with ’ … ’ before what does that mean to lua?

Even though I have long times like 1047s now haha, it’s great. Optimally I’ll add some code to turn that into the appropriate 17m 45s

But I’ll get to that later on.

Much appreciated

If you need to do styled text, you can use a webView, then you can do HTML and CSS to your hearts content to style text.  For many cases, a screen might have fixed text and I can make it look better in Photoshop than I can with straight up fonts.  LIke in my game OmniBlaster, I just did a Photoshop PSD file  that has all my credit text in it on the background.  Save out the one file then in my code, it’s just the background image and I don’t have to adjust any code.  If I change the credits, I just have to drop a new image file in my images folder.

I know for business apps or dynamic text, this isn’t the best of worlds.

I’ve made my styled text rendering open-source:

http://forums.coronalabs.com/topic/36617-here-is-my-styled-text-html-parsing-textwrapping-module/?p=189656

I’ve made my styled text rendering open-source:

http://forums.coronalabs.com/topic/36617-here-is-my-styled-text-html-parsing-textwrapping-module/?p=189656