Rotate Canvas
Rotating the canvas context
The rotateCanvas()
method rotates the canvas from the included point.
The x
and y
properties define the center of rotation.
Rotating an individual shape
Rather than rotating the entire canvas, you can rotate an individual shape using the rotate
properties.
Please note that you can offset the center of rotation by specifying the translateX
and translateY
properties.
Layers
Although it may seem slightly counterintuitive, the rotateCanvas()
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 rotating 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 rotating an individual shape.