I want to change the background color to a different color after each click. I have the background listener and everything working, I just need the background to change color after each click… Help!
Farid
I want to change the background color to a different color after each click. I have the background listener and everything working, I just need the background to change color after each click… Help!
Farid
You can change the color of display objects with object:setFillColor(), see http://docs.coronalabs.com/api/type/ShapeObject/setFillColor.html
You can also call setDefault()
http://docs.coronalabs.com/daily/api/library/display/setDefault.html
display.setDefault( "background", math.random(0,10)/10, math.random(0,10)/10, math.random(0,10)/10 )
Thanks for your replies. I know about the setFillColor as at the moment I can change the background color ONCE using
local function backgroundChange()
if event.phase == began then
background:setFillColor(0, 0.5, 0.5)
end
end
but that only changes the color once obvioulsy…
so roaminggamer, how would I add your method into my function??
Thankyou
I’m afraid I don’t understand the question. You’ll need to decide how you use that call.
Here is one of many possible ways:
local function onTouch( event ) if( event.phase == "ended" ) then display.setDefault( "background", math.random(0,10)/10, math.random(0,10)/10, math.random(0,10)/10 ) end return true end Runtime:addEventListener( "touch", onTouch )
As long as you don’t have images in front of the background, you should see the color change each you touch the screen and lift your finger.
Its okay I worked it out. I just added the line
background:setFillColor(math.random(0.1, 0.4), math.random(0.1, 0.9), math.random(0.1, 0.9))
Thankyou for your help!
You can change the color of display objects with object:setFillColor(), see http://docs.coronalabs.com/api/type/ShapeObject/setFillColor.html
You can also call setDefault()
http://docs.coronalabs.com/daily/api/library/display/setDefault.html
display.setDefault( "background", math.random(0,10)/10, math.random(0,10)/10, math.random(0,10)/10 )
Thanks for your replies. I know about the setFillColor as at the moment I can change the background color ONCE using
local function backgroundChange()
if event.phase == began then
background:setFillColor(0, 0.5, 0.5)
end
end
but that only changes the color once obvioulsy…
so roaminggamer, how would I add your method into my function??
Thankyou
I’m afraid I don’t understand the question. You’ll need to decide how you use that call.
Here is one of many possible ways:
local function onTouch( event ) if( event.phase == "ended" ) then display.setDefault( "background", math.random(0,10)/10, math.random(0,10)/10, math.random(0,10)/10 ) end return true end Runtime:addEventListener( "touch", onTouch )
As long as you don’t have images in front of the background, you should see the color change each you touch the screen and lift your finger.
Its okay I worked it out. I just added the line
background:setFillColor(math.random(0.1, 0.4), math.random(0.1, 0.9), math.random(0.1, 0.9))
Thankyou for your help!