Coloring Text

Hello guys,

I am trying to color a text but seems setFillColor doesn’t work. Below you can see my coding:

scoreText = display.newText (mydata.score, display.contentCenterX, 150, "Arial", 108) scoreText:setFillColor (1, 1, 0)

It shows me a black zero(mydata.score), when it should be a yellow zero. When I delete scoreText:setFillColor (1, 1, 0) it shows me a white zero, I guess that’s the default.

text = display.newText("test", 100, 100, "Arial", 100 ) text:setFillColor(1, 1, 0)

I tried to run this other than my coding. This one seems to be working. 

Where am I doing wrong?

Please help me.

Thanks in Advance,

Gurcan

I assume the score is a number? Does this line work?

scoreText = display.newText(tostring(mydata.score), display.contentCenterX, 150, "Arial", 108)

Maybe non-string arguments trick display.newText() into following its group or options table paths, so it ends up not loading some things?

That didn’t work either. I don’t know if this helps but here is my composer create:scene function http://pastebin.com/wR0H9Mre 

What you have should work if it’s not being altered somewhere else in your code. I put your two code lines in a new project and it showed a yellow 0.

You didn’t use “local” before the variable, so it will be a global unless it was defined elsewhere with “local”. As mentioned above, newText expects a text string so it’s good to use “tostring” on the text data if it may not be string data.

When testing to see if a string works, why didn’t you just change mydata.score to “test”? It implies you did this as a separate code test which doesn’t eliminate that there is an issue with how “scoreText” is being used.

The default text color is while (1, 1, 1) if setFillColor is not used. Black would occur if you set the color to 0 or (0,0,0)

So I figured out what was wrong. The problem was about my config.lua file which had “graphicsCompatibility = 1” in it. That’s why I couldn’t use “setFillColor(1, 1, 1)”, instead I needed to use setFillColor(255, 255, 255).

I guess, I wouldn’t be wrong to suggest people out there who are using Corona to consider checking their config.lua file after making sure everyting is working correctly.

Thanks to everyone who tried to help me.

Cheers!

I assume the score is a number? Does this line work?

scoreText = display.newText(tostring(mydata.score), display.contentCenterX, 150, "Arial", 108)

Maybe non-string arguments trick display.newText() into following its group or options table paths, so it ends up not loading some things?

That didn’t work either. I don’t know if this helps but here is my composer create:scene function http://pastebin.com/wR0H9Mre 

What you have should work if it’s not being altered somewhere else in your code. I put your two code lines in a new project and it showed a yellow 0.

You didn’t use “local” before the variable, so it will be a global unless it was defined elsewhere with “local”. As mentioned above, newText expects a text string so it’s good to use “tostring” on the text data if it may not be string data.

When testing to see if a string works, why didn’t you just change mydata.score to “test”? It implies you did this as a separate code test which doesn’t eliminate that there is an issue with how “scoreText” is being used.

The default text color is while (1, 1, 1) if setFillColor is not used. Black would occur if you set the color to 0 or (0,0,0)

So I figured out what was wrong. The problem was about my config.lua file which had “graphicsCompatibility = 1” in it. That’s why I couldn’t use “setFillColor(1, 1, 1)”, instead I needed to use setFillColor(255, 255, 255).

I guess, I wouldn’t be wrong to suggest people out there who are using Corona to consider checking their config.lua file after making sure everyting is working correctly.

Thanks to everyone who tried to help me.

Cheers!