Canvas rotate

From Sim Innovations Wiki
Revision as of 14:50, 19 December 2018 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


_rotate(angle, anchor_x, anchor_y)

_rotate is used to rotate all shapes drawn after this call to have rotation.

Info This function may only be called within a canvas draw callback

Return value

This function won't return any value.


# Argument Type Description
1 angle Number Angle of rotation in degrees.
2 anchor_x Number (Optional) Left point of the anchor point to rotate around
3 anchor_y Number (Optional) Top point of the anchor point to rotate around


canvas_add(0, 0, 200, 200, function()
  -- Set rotation of 10 degrees      

  -- Everything after this point will have the rotation applied to it

  -- Draw a red rectangle with rotation
  _rect(50, 50, 100, 100)

  -- Revert the rotation set before.
  -- From this point everything is drawn without any rotation	

  -- Draw a second smaller blue rectangle	
  _rect(75, 75, 50, 50)
Output of code above