The Rapid class provides a WebGL-based rendering engine.

Constructors

  • Constructs a new Rapid instance with the given options.

    Parameters

    Returns Rapid

Properties

backgroundColor: Color
canvas: HTMLCanvasElement
devicePixelRatio: number = ...
height: number
matrixStack: MatrixStack = ...
maxTextureUnits: number
projection: Float32Array
projectionDirty: boolean = true
textures: TextureCache = ...
width: number

Methods

  • Clears the canvas with the background color.

    Returns void

  • Clears the current mask by clearing the stencil buffer. This effectively removes any previously defined mask.

    Returns void

  • Ends the mask drawing process. This method configures the WebGL context to use the defined mask for subsequent rendering.

    Parameters

    Returns void

  • Ends the rendering process by rendering the current region.

    Returns void

  • Registers a custom render region with a specified name.

    Parameters

    • name: string

      The name of the region.

    • regionClass: typeof RenderRegion

      The class of the region to register.

    Returns void

  • Renders a circle

    Parameters

    • offsetX: number

      The X coordinate of the circle's center

    • offsetY: number

      The Y coordinate of the circle's center

    • radius: number

      The radius of the circle

    • color: Color = ...

      The color of the circle

    • segments: number = 32

      The number of segments to use when rendering the circle, default is 32

    Returns void

  • Renders graphics based on the provided options or array of Vec2 points.

    Parameters

    • offsetX: number = 0

      The X offset to apply when rendering the graphics. Defaults to 0.

    • offsetY: number = 0

      The Y offset to apply when rendering the graphics. Defaults to 0.

    • options: Vec2[] | IGraphicOptions

      Either an object containing graphic options or an array of Vec2 points.

    Returns void

    If options is an array of Vec2, it will be converted to an object with points property. If options is an object, it should contain points (array of Vec2) and optionally color and drawType.

  • Renders a line with the specified options.

    Parameters

    • offsetX: number = 0

      The X offset to apply when rendering the line. Defaults to 0.

    • offsetY: number = 0

      The Y offset to apply when rendering the line. Defaults to 0.

    • options: IRenderLineOptions

      The options for rendering the line, including points and color.

    Returns void

  • Renders a rectangle

    Parameters

    • offsetX: number

      The X coordinate of the top-left corner of the rectangle

    • offsetY: number

      The Y coordinate of the top-left corner of the rectangle

    • width: number

      The width of the rectangle

    • height: number

      The height of the rectangle

    • color: Color = ...

      The color of the rectangle

    Returns void

  • Renders a sprite with the specified texture, offset, and options.

    Parameters

    • texture: Texture

      The texture to render.

    • offsetX: number = 0

      The X offset for the sprite. Defaults to 0.

    • offsetY: number = 0

      The Y offset for the sprite. Defaults to 0.

    • Optionaloptions: Color | IRenderSpriteOptions

      Rendering options including color and custom shader.

    Returns void

  • Resizes the canvas and updates the viewport and projection matrix.

    Parameters

    • width: number

      The new width of the canvas.

    • height: number

      The new height of the canvas.

    Returns void

  • Restores the matrix state from the stack.

    Returns void

  • Saves the current matrix state to the stack.

    Returns void

  • Sets the mask type for rendering

    Parameters

    • type: MaskType

      The type of mask to apply

    Returns void

  • Sets the current render region by name and optionally a custom shader.

    Parameters

    • regionName: string

      The name of the region to set as current.

    • OptionalcustomShader: GLShader

      An optional custom shader to use with the region.

    Returns void

  • Starts drawing a mask using the stencil buffer. This method sets up the WebGL context to begin defining a mask area.

    Returns void

  • Starts the rendering process, resetting the matrix stack and clearing the current region.

    Parameters

    • clear: boolean = true

      Whether to clear the matrix stack. Defaults to true.

    Returns void

  • Transforms a point by applying the current matrix stack.

    Parameters

    • x: number

      The X coordinate of the point.

    • y: number

      The Y coordinate of the point.

    Returns number[] | Vec2

    The transformed point as an array [newX, newY].