Skip to content

Preventing object modification

Gastón Ambrogi edited this page Jul 6, 2016 · 11 revisions

There is a way to prevent object modification (like scaling, rotating, movement) of any object on canvas in real time. When an object has certain constrain property set to true it won't be allowed to be modified according to that constrain.

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 constrain.

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