Type Number Object DisplayObject Library display.* Revision 2019.3561 Keywords x, anchor See also Transforms and Anchors (guide) Group Programming (guide) object.anchorY display.setDefault()
This property allows you to control the alignment of the object along the x direction.
In general, the anchors of an object control how geometry is positioned relative to the object's origin. A value of
0 corresponds to left alignment, meaning the left edge of the object is aligned with the origin. A value of
0.5 corresponds to center alignment. A value of
1 corresponds to right alignment.
By default, anchor values must range from
1.0 and the anchor of new objects is set to
0.5, however these defaults can be modified (see below).
The default anchor can be changed for all display objects via display.setDefault().
Non-constrained anchors are allowed via the
"isAnchorClamped" setting of display.setDefault(). In this case, setting anchor values outside of the
1.0 range will position the anchor outside the bounds of the display object.
When you change an anchor value, the object's origin does not change. Instead, its geometry moves relative to its origin. See the Transforms and Anchors guide for more information.
local rect1 = display.newRect( 0, 0, 50, 50 ) rect1:setFillColor( 1, 0, 0 ) rect1.x = 100 rect1.y = 100 local rect2 = display.newRect( 0, 0, 50, 50 ) rect2:setFillColor( 1, 1, 1 ) rect2.anchorX = 0 rect2.x = 100 rect2.y = 100