StaticcameraGets a XY (left-top corner) of a camera's view. Could be used e.g. for drawing a game's HUD, or anything else that should be positioned against the viewport and against the global game canvas' coordinates.
Current camera's XY.
StaticclearFill 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.
StaticremoveRemoves the currently set clipping region, if any.
Previous clipping region in form of an array: [xy, wh]
StaticsetSets a new XY (left-top corner) of a camera's view
Previous camera's XY.
StaticsetSets 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]
StaticsetSets 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.
StatictakeTakes 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
));
StaticellipseDraws 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 and https://github.com/zingl/Bresenham
StaticellipseDraws 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 and https://github.com/zingl/Bresenham
StaticellipseDraws 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 and https://github.com/zingl/Bresenham
StaticlineDraws a line.
An implementation of Bresenham's Algorithm by Alois Zingl: http://members.chello.at/easyfilter/bresenham.html and https://github.com/zingl/Bresenham
StaticpixelDraws a single colored pixel.
StaticpixelsDraws 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.
Optionalopts: { OptionalcenterOptionalflipOptionalscaleStaticrectDraws a rectangle, boundary only.
Left-top corner.
StaticrectDraws a rectangle, filled.
Left-top corner.
StaticrectDraws a rectangle, boundary only, and fills the entire canvas around the rectangle.
Left-top corner.
StaticsetAllows to define a color mapping from the sprite colors to the desired ones.
Previously used color mapping
StaticspriteDraws a given sprite.
Optionalopts: { OptionalcenterOptionalflipOptionalscaleStaticmeasureMeasures the space that would be occupied by the text if it was drawn on the canvas.
Optionalopts: { OptionalcenterOptionalscaleconst 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)
StaticsetSets 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);
StaticsetSets 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
StatictextDraws a text.
Optionalopts: { OptionalcenterOptionalscale
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