object.fill

Type Paint
Object ShapeObject
Library display.*
Revision Release 2024.3703
Keywords fill
See also stroke
Filters/Generators/Composites (guide)

Overview

For object fills, Corona uses the concept of paint. The fill of a shape refers to the interior area of the shape. When you assign a paint to a fill, you control how the interior area of the shape is rendered.

Paint Types

Examples

Solid Color Fill
local paint = { 1, 0, 0.5 }
local rect = display.newRect( 200, 300, 300, 300 )
rect.fill = paint
Bitmap Image Fill
local paint = {
    type = "image",
    filename = "texture1.png"
}

local rect = display.newRect( 200, 200, 300, 300 )
rect.fill = paint
Composite Fill
local paint = {
    type = "composite",
    paint1 = { type="image", filename="wood.png" },
    paint2 = { type="image", filename="dust.png" }
}

local rect = display.newRect( 200, 200, 300, 300 )
rect.fill = paint
rect.fill.effect = "composite.average"
Gradient Fill
local paint = {
    type = "gradient",
    color1 = { 1, 0, 0.4 },
    color2 = { 1, 0, 0, 0.2 },
    direction = "down"
}

local rect = display.newRect( 200, 200, 300, 300 )
rect.fill = paint
Image Sheet Frame Fill
local options =
{
    width = 40,
    height = 100,
    numFrames = 8,
    sheetContentWidth = 160,  -- width of original 1x size of entire sheet
    sheetContentHeight = 200  -- height of original 1x size of entire sheet
}
local imageSheet = graphics.newImageSheet( "textures.png", options )

local paint = {
    type = "image",
    sheet = imageSheet,
    frame = 2
}

local rect = display.newRect( 200, 200, 300, 300 )
rect.fill = paint
Camera Source Fill
if ( system.getInfo("environment") ~= "simulator" ) then
    display.setDefault( "cameraSource", "front" )   --front-facing camera
    --display.setDefault( "cameraSource", "back" )  --back-facing camera
end

local rect = display.newRect( 200, 200, 300, 300 )
rect.fill = { type = "camera" }