object.stroke

类型 绘制
对象 ShapeObject
display.*
修订 版本 2024.3703
关键词 描边
另请参阅 填充
滤镜/生成器/复合 (指南)

概述

对于对象描边,Corona 使用了 绘制 的概念。形状的描边指的是形状的边界。在向描边分配 绘制 时,你控制着边界的呈现方式。

描边以中心 (对象边界内部和外部均等) 方式绘制。

绘制类型

示例

纯色描边
local paint = { 1, 0, 0.5 }
local rect = display.newRect( 200, 300, 300, 300 )
rect.stroke = paint
rect.strokeWidth = 4
位图图像描边
local paint = {
    type = "image",
    filename = "texture1.png"
}

local rect = display.newRect( 200, 200, 300, 300 )
rect.stroke = paint
rect.strokeWidth = 4
复合描边
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"
渐变描边
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
图像图层帧描边
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