Type Function Object ShapeObject Library display.* Return value none Revision Release 2023.3686 Keywords setFillColor, color, fill, vector See also object:setStrokeColor() display.newRect() display.newRoundRect() display.newCircle() display.newText() display.newPolygon()
Sets the fill color of vector and text objects. Also applies a tint to image objects.
object:setFillColor( gray ) object:setFillColor( gray, alpha ) object:setFillColor( red, green, blue ) object:setFillColor( red, green, blue, alpha ) object:setFillColor( gradient )
Numbers. Numbers between 0
and 1
that represent the corresponding value for that channel. alpha
represents the opacity of the fill color/tint.
Table. See the gradient fill example below.
If you are passing a table of color values to this function, the table must be unpacked so that the color values are dictated properly:
local myText = display.newText( "hello", 0, 0, native.systemFontBold, 12 ) local colorTable = { 1, 0, 0, 0.5 } myText:setFillColor( unpack(colorTable) )
local vertices = { 0,-110, 27,-35, 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35 } local star = display.newPolygon( 300, 300, vertices ) star:setFillColor( 1, 0.2, 0.2 )
local myText = display.newText( "hello", 0, 0, native.systemFontBold, 12 ) myText:setFillColor( 1, 0.2, 0.2 )
local rect = display.newRect( 0, 0, 100, 200 ) local gradient = { type="gradient", color1={ 1, 1, 1 }, color2={ 0.8, 0.8, 0.8 }, direction="down" } rect:setFillColor( gradient )
local image = display.newImage( "image.png" ) image:setFillColor( 0.72, 0.9, 0.16, 0.78 ) -- Tints image green