object.xScale

Type Number
Object DisplayObject
Library display.*
Revision Release 2024.3703
Keywords x, scale, object scaling, size
See also object.yScale

Overview

Retrieve or change the scale of the object in the x direction. The scaling occurs around the object's anchor point.

You can flip a display object horizontally by passing a negative value to object.xScale as seen in the example below.

Valid examples include 1.0 for 100%, 2.0 for 200%, or 0.5 for 50%.

Gotchas

Example

local rect1 = display.newRect( 25, 75, 50, 50 )
rect1:setFillColor( 1, 1, 1 )

-- Flip the rectangle horizontally
rect1.xScale = -1

local rect2 = display.newRect( 125, 75, 50, 50 )
rect2:setFillColor( 1, 0, 0 )

rect2.xScale = 2  -- Change the horizontal scale to 200%