display.newRoundedRect()

Type Function
Library display.*
Return value ShapeObject
Revision Release 2024.3703
Keywords rounded rectangle, rectangle, vector object
See also Shapes — Paths, Fills, Strokes (guide)
Display Objects (guide)

Overview

Creates a rounded rectangle object. The corners are rounded by quarter circles of a specified radius value. The local origin is at the center of the rectangle and the anchor point is initialized to this local origin.

Gotchas

If the corner radius is greater than half of the rectangle's width or height, the actual radius will be decreased so that the rounded rectangle is rendered as a "capsule" shape.

Syntax

display.newRoundedRect( [parent,] x, y, width, height, cornerRadius )
parent (optional)

GroupObject. An optional display group in which to insert the rounded rectangle.

x / y (required)

Numbers. The x and y coordinates for the center of the rectangle.

width / height (required)

Numbers. Width and height of the rectangle.

cornerRadius (required)

Number. Corners are rounded by quarter circles of this radius value.

Properties

(Inherits properties from ShapeObject)

Rounded rectangle objects have a path property which lets you modify the radius, width, and height:

object.path.radius

Number. Radius of the corners. This cannot be set to a value larger than half the width or height of the rectangle.

object.path.height

Number. Height of the rectangle.

object.path.width

Number. Width of the rectangle.

Example

local myRoundedRect = display.newRoundedRect( 0, 0, 150, 50, 12 )
myRoundedRect.strokeWidth = 3
myRoundedRect:setFillColor( 0.5 )
myRoundedRect:setStrokeColor( 1, 0, 0 )