Static
clearFill the entire canvas with a given color. It's a method which you would typically call as the very first inside BeetPx.setOnDraw in order to not clear the canvas from what was drawn in the previous game loop iteration.
Static
removeRemoves the currently set clipping region, if any.
Previous clipping region in form of an array: [xy, wh]
Static
setSets a new XY (left-top corner) of a camera's viewport
Previous camera's XY.
Static
setSets a clipping region, which is a rectangular boundary which limits all the subsequent drawing to happen only within it.
Previous clipping region in form of an array: [xy, wh]
Static
setSets a drawing pattern to use. A drawing pattern is a 4x4 definition of which
pixels should be drawn with the primary
and which with the secondary
of
BpxPatternColors.
Previously used pattern.
Static
takeTakes a snapshot of the canvas, so it can be later used together with BpxCanvasSnapshotColorMapping. Can be used e.g. for drawing a lighter pixels around light sources.
https://github.com/beetrootpaul/beetpx-examples/tree/main/canvas-snapshot
$d.takeCanvasSnapshot();
$d.ellipseFilled(lightXy.sub(lightRadius), $v(lightRadius * 2), BpxCanvasSnapshotColorMapping.of(
(color: BpxRgbColor | null): BpxRgbColor | null =>
color
? $rgb((50 + color.r) * 1.25, (30 + color.g) * 1.2, (10 + color.b) * 1.05)
: null
));
Static
ellipseDraws an ellipse, boundary only.
Left-top corner of a rectangle that the ellipse would fit into.
An implementation of Bresenham's Algorithm by Alois Zingl: http://members.chello.at/easyfilter/bresenham.html
Static
ellipseDraws an ellipse, filled.
Left-top corner of a rectangle that the ellipse would fit into.
An implementation of Bresenham's Algorithm by Alois Zingl: http://members.chello.at/easyfilter/bresenham.html
Static
ellipseDraws an ellipse, boundary only, and fills the entire canvas around the ellipse.
Left-top corner of a rectangle that the ellipse would fit into.
An implementation of Bresenham's Algorithm by Alois Zingl: http://members.chello.at/easyfilter/bresenham.html
Static
lineDraws a line.
An implementation of Bresenham's Algorithm by Alois Zingl: http://members.chello.at/easyfilter/bresenham.html
Static
pixelDraws a single colored pixel.
Static
pixelsDraws pixels based on a visual 2d representation, defined by BpxPixels. Helpful for quickly drawing a shape that you don't have a sprite for in your spritesheet.
Optional
opts: { Optional
centerOptional
flipOptional
scaleStatic
rectDraws a rectangle, boundary only.
Left-top corner.
Static
rectDraws a rectangle, filled.
Left-top corner.
Static
rectDraws a rectangle, boundary only, and fills the entire canvas around the rectangle.
Left-top corner.
Static
setAllows to define a color mapping from the sprite colors to the desired ones.
Previously used color mapping
Static
spriteDraws a given sprite.
Optional
opts: { Optional
centerOptional
flipOptional
scaleStatic
measureMeasures the space that would be occupied by the text if it was drawn on the canvas.
Optional
opts: { Optional
centerOptional
scaleconst line1Wh = $d.measureText(textLine1).wh;
const line2Wh = $d.measureText(textLine2).wh;
const line3Wh = $d.measureText(textLine3).wh;
const totalW = Math.max(line1Wh.x, line2Wh.x, line3Wh.x);
const totalH = line1Wh.y + line2Wh.y + line3Wh.y;
const leftTop = $x.canvasSize.div(2).sub(totalW / 2, totalH / 2)
Static
setSets a font to be used for subsequent text drawing.
Previously used font
https://github.com/beetrootpaul/beetpx-examples/tree/main/fonts
const prevFont = $d.setFont($font_saint11Minimal4);
$d.text("hello!", $v(10), $rgb_red);
$d.setFont(prevFont);
Static
setSets color markers to be used for subsequent text drawing. Color markers are used inside text to indicate places where a color should change to another one.
Previously used color markers
Static
textDraws a text.
Optional
opts: { Optional
centerOptional
scale
One of 3 main API entry points. This one provides you with the drawing capabilities. Its methods are supposed to be called from either inside BeetPx.setOnStarted or BeetPx.setOnDraw callback.
Example