object.x

Type Number
Object DisplayObject
Library display.*
Revision Release 2022.3683
Keywords x, position
See also object.y

Overview

Specifies the x position (in local coordinates) of the object relative to its parent — specifically, the x position of the object's anchorX point relative to its parent. Changing this value will move the object in the x direction.

Gotchas

This cannot be used on a physical body during a collision event. However, your collision handler may set a flag or include a time delay via timer.performWithDelay() so that the action can occur in the next application cycle or later. See the Collision Detection guide for a complete list of which APIs and methods are subject to this rule.

Example

local rect = display.newRect( 0, 0, 50, 50 )
rect:setFillColor( 1, 1, 1 )

rect.x = 100