ridder
Version:
A straightforward game engine for simple data-driven games in JavaScript
105 lines (104 loc) • 4.33 kB
TypeScript
import { Circle } from "./circle.js";
import { Polygon } from "./polygon.js";
import { Rectangle } from "./rectangle.js";
import { Vector } from "./vector.js";
export type TextAlign = "left" | "center" | "right";
export type TextBaseline = "top" | "middle" | "bottom";
/**
* Clear the background using the set `background` color.
*
* @see {@link setBackgroundColor}
*/
export declare function clearBackground(): void;
/**
* Reset the transformation matrix, also known as the identity matrix.
*/
export declare function resetTransform(): void;
/**
* Move the origin of the transformation matrix by the given x and y values.
*/
export declare function translateTransform(x: number, y: number): void;
/**
* Additionally scale the transformation matrix by the given x and y values.
*/
export declare function scaleTransform(x: number, y: number): void;
/**
* Rotate the transformation matrix by the given degrees.
*/
export declare function rotateTransform(degrees: number): void;
/**
* Add the camera transform (position, shake) to the current transformation matrix.
* @param scrollX - The scrolling factor for the x-axis, you can add a parallax effect by setting this to a value between 0 and 1.
* @param scrollY - The scrolling factor for the y-axis, you can add a parallax effect by setting this to a value between 0 and 1.
*/
export declare function applyCameraTransform(scrollX?: number, scrollY?: number): void;
/**
* Draw a texture from the cache onto the canvas.
*/
export declare function drawTexture(id: number, x: number, y: number): void;
/**
* Draw a sprite (a region within a texture) from the cache onto the canvas.
*/
export declare function drawSprite(id: number, x: number, y: number): void;
/**
* Draw text onto the canvas.
* @param color - A color value, e.g. `white` or `#ffffff`
* @param align - The horizontal alignment of the text
* @param baseline - The vertical alignment of the text
*/
export declare function drawText(text: string, x: number, y: number, color?: string, align?: TextAlign, baseline?: TextBaseline): void;
/**
* Draw outlined text onto the canvas.
* @param color - A color value, e.g. `white` or `#ffffff`
* @param outlineColor - A color value, e.g. `white` or `#ffffff`
* @param outlineMode - The mode of the outline. Either "circle" or "square".
* @param align - The horizontal alignment of the text
* @param baseline - The vertical alignment of the text
*/
export declare function drawTextOutlined(text: string, x: number, y: number, color?: string, outlineColor?: string, outlineMode?: "circle" | "square", align?: TextAlign, baseline?: TextBaseline): void;
/**
* Draw a rectangle onto the canvas.
*/
export declare function drawRect(x: number, y: number, w: number, h: number, color?: string, fill?: boolean): void;
/**
* Draw a rectangle onto the canvas.
*/
export declare function drawRectInstance(r: Rectangle, color?: string, fill?: boolean): void;
/**
* Draw a circle onto the canvas.
*/
export declare function drawCircle(x: number, y: number, r: number, color?: string, fill?: boolean): void;
/**
* Draw a circle onto the canvas.
*/
export declare function drawCircleInstance(c: Circle, color?: string, fill?: boolean): void;
/**
* Draw a polygon onto the canvas.
*/
export declare function drawPolygon(x: number, y: number, points: Array<Vector>, color?: string, fill?: boolean): void;
/**
* Draw a polygon onto the canvas.
*/
export declare function drawPolygonInstance(p: Polygon, color?: string, fill?: boolean): void;
/**
* Draw a line onto the canvas.
*/
export declare function drawLine(x1: number, y1: number, x2: number, y2: number, color?: string, segments?: number[]): void;
/**
* Set the background color of the canvas.
*/
export declare function setBackgroundColor(color: string): void;
/**
* Use a font from the cache for the upcoming text rendering.
*/
export declare function setFont(id: number): void;
/**
* Set the alpha for the upcoming drawings.
*/
export declare function setAlpha(alpha: number): void;
/**
* Set the blend mode for the upcoming drawings.
*
* For an overview of blend modes, see the bottom of [this](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation) MDN page.
*/
export declare function setBlendMode(mode: GlobalCompositeOperation): void;