I’m attempting to change the text and background color on the fly in my app. The text in within a group. I’m able to change the background color but not the text color. i’m using display.newText and setTextColor. I’ve created a button and within the event i’m able to change the background color but not the text color. Baasically it changes from black BG and white Text to white BG and black text. I’m a newbe so any help would be appreciated. Thanks! [import]uid: 23160 topic_id: 5646 reply_id: 305646[/import]
I can’t help you trouble shoot your code, because it wasn’t posted. But I wrote this demo and it seems to work fine. Double check your code against this:
[lua]function strobe() – Function called to switch colours
if txt.color == “light” then – If txt is currently light then change to dark
txt:setTextColor( 50,50,50 )
back:setFillColor( 255,255,255 )
txt.color = “dark”
else – If txt is currently dark then change to light
txt:setTextColor( 255,255,255 )
back:setFillColor( 50,50,50 )
txt.color = “light”
end
timer.performWithDelay( 1000, strobe ) – Run this function again in 1 second
end
txt = display.newText( “Hello”, 0, 0, native.systemFontBold, 20 ) – Create the text obejct
txt.x = display.contentWidth * 0.5 – Position it to centrescreen
txt.y = display.contentHeight * 0.5
txt:setTextColor( 255,255,255 )
txt.color = “light” – Set initial colour to light
back = display.newRect( 0, 0, txt.width * 1.1, txt.height * 1.1 ) – Create a rectangle for background slightly larger than text
back.x = txt.x
back.y = txt.y
back:setFillColor( 50,50,50 )
back:toBack() – Send rectangle to the back of the display group so we can see the text
timer.performWithDelay( 1000, strobe ) – Change colours in 1 second[/lua] [import]uid: 11393 topic_id: 5646 reply_id: 19353[/import]
Thanks, this helped a lot! [import]uid: 23160 topic_id: 5646 reply_id: 20079[/import]