Monday, 28 October 2013

How to fill a rectangle with gradient in corona SDK

Corona has a property called graphics.newGradient(), which will be useful for coloring/filling your rectangle with suitable color gradient.



-- First create the rectangle --
local myRectangle = display.newRect( 0, 0, 200, 200 )



-- Then create the gradient method --
local g = graphics.newGradient(
                            { 255, 255, 255 },     -- This is the first color array
                            { 200, 200, 200 },     -- This is the second color array
                             "down" )                  --[[ This is the gradient direction.
                                                                    Default is "down"
                                                                    Others are "up","right" and "left". --]]


-- Now fill your rectangle with the created gradient as: --
myRectangle:setFillColor( g )





No comments:

Post a Comment