 |
Canvas
The canvas object provides a system-independent interface for drawing shapes and textures on the screen.
Notice that canvas itself does not have a position in the game world.
Also take note that the all canvases are infinite in size.
The center of every canvas is the origin point (0, 0) where the positive x-axis points right and the positive y-axis points up.
Rendering vector shapes on the canvas is a two-step process.
First, we define the contour of the shape that we want to draw.
This is done through a series of "move_to" and "line_to" calls to the canvas.
Nothing will be drawn, until we make a final call to either the "stroke" or "fill" method.
The former renders our path as a series of straight lines whereas the latter will produce a closed shape of uniform color.
To output a texture on the canvas, we start with a call to the "set_source_image" method.
This method accepts an image object and a position in canvas coordinates.
Again, nothing is drawn until we call the "paint" method which will render and reset the currently selected source image.
Non-Constant Methods
- circle ( number radius )
Plots a closed circular sub-shape from a given radius. Does not change the initial position of the pen
- close_path ( )
Plots a straight line from the pen position to the first point of the current sub-path. Closes any currently open sub-path
- copy ( Canvas source )
Copies the contents of a source canvas
- curve_to ( Point pt, Point handle )
curve_to ( number pt_x, number pt_y, number handle_x, number handle_y ) Plots a quadratic bezier curve from the pen to a given point using a third point as a handle
- ellipse ( number width, number height )
Plots a closed elliptical sub-shape from a given width and height. Does not change the initial position of the pen
- fill ( )
Fills each sub-path with the current brush color. Deletes all sub-paths defined thus far
- fill_preserve ( )
Fills each sub-path with the current brush color
- line_to ( Point pt )
line_to ( number pt_x, number pt_y ) Plots a straight line from the pen to a given end point in local coordinates
- move_to ( Point pt )
move_to ( number pt_x, number pt_y ) Moves the canvas pen to a given point in local coordinates. Closes any currently open sub-path
- paint ( )
Draws all images previously set to the canvas
- rectangle ( number width, number height )
Plots a closed rectangular sub-shape from a given width and height. Does not change the initial position of the pen
- reference ( Canvas source )
Selects the source canvas as a reference
- rel_line_to ( Point pt )
rel_line_to ( number pt_x, number pt_y ) Plots a straight line from the pen to a given end point relative to the current pen position
- rel_move_to ( Point pt )
rel_move_to ( number pt_x, number pt_y ) Moves the canvas pen to a given point relative to the current pen position. Closes any currently open sub-path
- set_fill_style ( Color brush )
set_fill_style ( Color brush, number alpha ) Sets the canvas brush color and alpha value
- set_line_style ( number thickness )
set_line_style ( number thickness, Color pen )
set_line_style ( number thickness, Color pen, number alpha ) Sets the thickness, color and alpha value of the canvas pen
- set_source_image ( Image img )
set_source_image ( Image img, Point pt )
set_source_image ( Image img, number pt_x, number pt_y ) Sets an image at a given position onto the canvas
- square ( number side )
Plots a closed square sub-shape from a given side. Does not change the initial position of the pen
- stroke ( )
Draws a beveled line along each sub-path with the current pen color and line width. Deletes all sub-paths defined thus far
- stroke_preserve ( )
Draws a beveled line along each sub-path with the current pen color and line width
|