object.stroke

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

Overview

For object strokes, Corona uses the concept of paint. The stroke of a shape refers to the boundary of the shape. When you assign a paint to a stroke, you control how the boundary is rendered.

Strokes are painted centrally (equally inside and outside) the object's boundary.

Paint Types

Examples

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

local rect = display.newRect( 200, 200, 300, 300 )
rect.stroke = paint
rect.strokeWidth = 4
Composite Stroke
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.stroke = paint
rect.strokeWidth = 4
rect.stroke.effect = "composite.average"
Gradient Stroke
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.stroke = paint
rect.strokeWidth = 4
Image Sheet Frame Stroke
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.stroke = paint
rect.strokeWidth = 4