Skip to content

Preventing object modification (movement)

Lars edited this page Apr 1, 2016 · 1 revision

To completely prevent both scaling and rotation of an object, you can set hasControls to false. This will prevent display of scaling and rotation controls as well. However it does not disable movement of the object.

For finer-grained constraining of object modification (like scaling, rotating, movement) of any object on canvas in real time, using constraint properties. When an object has certain constraint property set to true it won't be allowed to be modified according to that constraint.

For example, target.lockRotation = true — where target is a reference to an object in question — will prevent object from being rotated. Similarly, target.lockMovementX will prevent horizontal movement (but allowing vertical one), and target.lockMovementY — vertical one (but allowing horizontal).

These constraining properties can be combined. For example, target.lockMovementX = target.lockMovementY = true will prevent object from being moved in any direction. However, it would still be possible to rotate or scale it (as long as other constraining properties are not in a play).

Changing value back to false at any time, will remove corresponding constraint.

The list of these constraining properties is as follows:

  • lockMovementX
    Prevents horizontal movement
  • lockMovementY
    Prevents vertical movement
  • lockScalingX
    Prevents horizontal scaling
  • lockScalingY
    Prevents vertical scaling
  • lockUniScaling
    Prevents scaling in either X or Y direction but not in both. In other words, prevents non-proportional scaling of an object.
  • lockRotation
    Prevents rotation