object:setFillColor()

Type Function
Object ShapeObject
Library display.*
Return value none
Revision 2017.3179
Keywords setFillColor, color, fill, vector
See also object:setStrokeColor()
display.newRect()
display.newRoundRect()
display.newCircle()
display.newText()
display.newPolygon()

Overview

Sets the fill color of vector and text objects. Also applies a tint to image objects.

Syntax

object:setFillColor( gray )
object:setFillColor( gray, alpha )
object:setFillColor( red, green, blue )
object:setFillColor( red, green, blue, alpha )
object:setFillColor( gradient )
gray, red, green, blue, alpha (optional)

Numbers. Numbers between 0 and 1 that represent the corresponding value for that channel. alpha represents the opacity of the fill color/tint.

gradient (optional)

Table. See the gradient fill example below.

Gotchas

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) )

Examples

Vector Object Fill
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 )
Text Object Fill
local myText = display.newText( "hello", 0, 0, native.systemFontBold, 12 )

myText:setFillColor( 1, 0.2, 0.2 )
Gradient Fill
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 )
Image Tint
local image = display.newImage( "image.png" )
image:setFillColor( 0.72, 0.9, 0.16, 0.78 )  -- Tints image green