Background color fade

I want to make my background fade slowly to different colors . Can someone help me ?

I’d make a rectangle that covers the screen and use color transition from here:

http://github.com/roaminggamer/SSKLegacy/blob/master/ssk/extensions/transition_color.lua

Just copy that file to your root folder, then

local tc = require "transition\_color" local cx = display.contentCenterX local cy = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local back = display.newRect( cx, cy, fullw, fullh ) local color1 = { 1, 1, 1 } local color2 = { 1, 1, 0 } back:setFillColor( unpack( color1 ) ) tc.fromtocolor(back, color1, color2, 1000 )

I am getting this error :

main.lua:14: attempt to index local ‘tc’ (a boolean value)

line 14

tc.fromtocolor(back, color1, color2, 1000 )

http://github.com/roaminggamer/SSKLegacy/blob/master/ssk/extensions/transition_color.lua

 

Just copy that file to your root folder.

 

There is one small mistake in my code, but you can catch this be reading the transition module.  Please read the module and you’ll see it.

tc.fromtocolor(back, color1, color2, 1000 )

should be:

transition.fromtocolor(back, color1, color2, 1000 )

If you look at the transition_color.lua module,  you’ll  see this on line 39

function transition.fromtocolor(obj, colorFrom, colorTo, time, delay, ease)

I’m adding the new function to the transition module (extending it).  Also, I don’t return anything from this module, so my the require call returns nothing.  

There is an error here 

 local aDiff = tcolor[4] - fcolor[4] ;

But I don’t see anything wrong

Grumble… I don’t test every piece of sample usage code I type in.  I expect folks to have rudimentary debugging skills, thus if I typo something they’ll find it.

That error is pretty clearly saying it can’t find the fourth color value…

For future reference.  This can be easily be debugged with a couple print statements.  Put a print statement in there to check the values of tcolor[4] and fcolor[4].

 print( 'tcolor[4] ==', tcolor[4] ) print( 'fcolor[4] ==', fcolor[4] ) local aDiff = tcolor[4] - fcolor[4]

You would then see they were nil and be able to work backwards to the root of the issue from there.

A cursory glance at that line, and the sample show this (only three elements per color):

local color1 = { 1, 1, 1 } local color2 = { 1, 1, 0 }

So a fix would be:

local color1 = { 1, 1, 1, 1 } local color2 = { 1, 1, 0, 1 }

Note: I know for a fact this module works fine, so regardless of typos in my sample usage I know it will work once you debug any typos I may have made in my sample usage.  This is my last response on this thread.

PS - I’m a little frustrated, because I feel like you didn’t try to debug this.  I am still happy to help you in the future, but I expect you to meet me in the middle with a little debugging on your own if things go wrong.

PPS - Often times the ‘answers’ I provide here are error free, but I’m not perfect.  I write these answers in spare minutes between tasks and in my pell-mell rush I sometimes overlook something.

Please only ask your question once. There are three threads going. I’m going to lock two them. Please use the one thread to solve this issue.

https://forums.coronalabs.com/topic/65695-gradient-paint-background/

Rob

I’d make a rectangle that covers the screen and use color transition from here:

http://github.com/roaminggamer/SSKLegacy/blob/master/ssk/extensions/transition_color.lua

Just copy that file to your root folder, then

local tc = require "transition\_color" local cx = display.contentCenterX local cy = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentHeight local back = display.newRect( cx, cy, fullw, fullh ) local color1 = { 1, 1, 1 } local color2 = { 1, 1, 0 } back:setFillColor( unpack( color1 ) ) tc.fromtocolor(back, color1, color2, 1000 )

I am getting this error :

main.lua:14: attempt to index local ‘tc’ (a boolean value)

line 14

tc.fromtocolor(back, color1, color2, 1000 )

http://github.com/roaminggamer/SSKLegacy/blob/master/ssk/extensions/transition_color.lua

 

Just copy that file to your root folder.

 

There is one small mistake in my code, but you can catch this be reading the transition module.  Please read the module and you’ll see it.

tc.fromtocolor(back, color1, color2, 1000 )

should be:

transition.fromtocolor(back, color1, color2, 1000 )

If you look at the transition_color.lua module,  you’ll  see this on line 39

function transition.fromtocolor(obj, colorFrom, colorTo, time, delay, ease)

I’m adding the new function to the transition module (extending it).  Also, I don’t return anything from this module, so my the require call returns nothing.  

There is an error here 

 local aDiff = tcolor[4] - fcolor[4] ;

But I don’t see anything wrong

Grumble… I don’t test every piece of sample usage code I type in.  I expect folks to have rudimentary debugging skills, thus if I typo something they’ll find it.

That error is pretty clearly saying it can’t find the fourth color value…

For future reference.  This can be easily be debugged with a couple print statements.  Put a print statement in there to check the values of tcolor[4] and fcolor[4].

 print( 'tcolor[4] ==', tcolor[4] ) print( 'fcolor[4] ==', fcolor[4] ) local aDiff = tcolor[4] - fcolor[4]

You would then see they were nil and be able to work backwards to the root of the issue from there.

A cursory glance at that line, and the sample show this (only three elements per color):

local color1 = { 1, 1, 1 } local color2 = { 1, 1, 0 }

So a fix would be:

local color1 = { 1, 1, 1, 1 } local color2 = { 1, 1, 0, 1 }

Note: I know for a fact this module works fine, so regardless of typos in my sample usage I know it will work once you debug any typos I may have made in my sample usage.  This is my last response on this thread.

PS - I’m a little frustrated, because I feel like you didn’t try to debug this.  I am still happy to help you in the future, but I expect you to meet me in the middle with a little debugging on your own if things go wrong.

PPS - Often times the ‘answers’ I provide here are error free, but I’m not perfect.  I write these answers in spare minutes between tasks and in my pell-mell rush I sometimes overlook something.

Please only ask your question once. There are three threads going. I’m going to lock two them. Please use the one thread to solve this issue.

https://forums.coronalabs.com/topic/65695-gradient-paint-background/

Rob