Canvas
Definition
A two-dimensional touch-sensitive rectangular panel on which drawing can be done and sprites can be moved.
The BackgroundColor
, PaintColor
, BackgroundImage
, Width
, and Height
of the Canvas
can be set in either the Designer or in the Blocks Editor. The Width
and Height
are measured in pixels and must be positive.
Any location on the Canvas
can be specified as a pair of (X, Y)
values, where
- X is the number of pixels away from the left edge of the
Canvas
- Y is the number of pixels away from the top edge of the
Canvas
There are events to tell when and where a Canvas
has been touched or a Sprite (ImageSprite
or Ball
) has been dragged. There are also methods for drawing points, lines, circles, shapes, arcs, and text.
Properties
- BackgroundColor
- Specifies the Canvas’s background color as an alpha-red-green-blue integer, i.e.,
0xAARRGGBB
. An alpha of00
indicates fully transparent andFF
means opaque. The background color only shows if there is no background image. - BackgroundImage
- Specifies the name of a file containing the background image for the
Canvas
. - BackgroundImageinBase64
- Set the background image in Base64 format. This requires API level >= 8. For devices with API level less than 8, setting this will end up with an empty background.
- ExtendMovesOutsideCanvas
- Determines whether moves can extend beyond the canvas borders. Default is false. This should normally be false, and the property is provided for backwards compatibility.
- FontSize
- Specifies the font size of text drawn on the Canvas.
- Height
- Specifies the
Canvas
’s vertical height, measured in pixels. - HeightPercent
- Specifies the
Canvas
’s vertical height as a percentage of theScreen
’sHeight
. - LineWidth
- Specifies the width of lines drawn on the Canvas.
- PaintColor
- Specifies the paint color as an alpha-red-green-blue integer, i.e.,
0xAARRGGBB
. An alpha of00
indicates fully transparent andFF
means opaque. - TapThreshold
- Specifies the movement threshold to differentiate a drag from a tap.
- TextAlignment
- Specifies the alignment of the canvas’s text: center, normal (starting at the specified point in
DrawText
orDrawTextAtAngle
), or opposite (ending at the specified point inDrawText
orDrawTextAtAngle
). - Visible
- Specifies whether the
Canvas
should be visible on the screen. Value istrue
if theCanvas
is showing andfalse
if hidden. - Width
- Specifies the horizontal width of the
Canvas
, measured in pixels. - WidthPercent
- Specifies the horizontal width of the
Canvas
as a percentage of theScreen
’sWidth
.