Translate Canvas
The translateCanvas()
method translates the canvas by the given values.
The translate
property
You can also set both the translateX
and translateY
properties using the translate
property.
Translating an individual shape
Rather than translating the entire canvas, you can translate an individual shape using any of these three properties.
Please note that translating a shape changes its center of transformation (which will affect how the layer is rotated).
Layers
Although it may seem slightly counterintuitive, the translateCanvas()
method can actually be drawn as a layer. This allows for applying canvas transformations when drawing layers.
To do this, set the layer
property to true
, just as you would to make any other shape a layer. In addition, just as you can with any other type of layer, you can give this layer a name using the name
property.
However, whenever you’re done translating the canvas, you must restore the transformation using the restoreCanvas()
method.
Notes
To revert to the canvas’s previous state, call the restoreCanvas()
method. However, you do not need to call this method when translating an individual shape.