Type Number Object DisplayObject Library display.* Revision Current Public Release (2018.3326) Keywords x, scale, object scaling, size See also object.yScale
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%.
xScale property can also be set as part of the object:scale() function.
When a display object is converted into a physics object, scaling the object will change the visual size, but it will not affect how the physics engine regards the object size. This could result in unpredictable results when interacting with other physics bodies.
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%