The Matter.Render module is a simple canvas based renderer for visualising instances of Matter.Engine. It is intended for development and debugging purposes, but may also be suitable for simple games. It includes a number of drawing options including wireframe, vector with support for sprites and viewports.

Hierarchy

  • default

Constructors

Properties

_cancelAnimationFrame: ((handle) => void) & ((handle) => void) = ...

Type declaration

    • (handle): void
    • Parameters

      • handle: number

      Returns void

Type declaration

    • (handle): void
    • Parameters

      • handle: number

      Returns void

_goodDelta: number = ...
_goodFps: number = 30
_requestAnimationFrame: ((callback) => number) & ((callback) => number) = ...

Type declaration

    • (callback): number
    • Parameters

      • callback: FrameRequestCallback

      Returns number

Type declaration

    • (callback): number
    • Parameters

      • callback: FrameRequestCallback

      Returns number

Methods

  • Applies the background to the canvas using CSS.

    Parameters

    • render: IRender
    • background: string

    Returns void

    Method

    applyBackground

  • Parameters

    • width: number
    • height: number

    Returns HTMLCanvasElement

    canvas

    Method

    _createCanvas

  • Gets the pixel ratio of the canvas.

    Parameters

    • Optional _canvas: HTMLCanvasElement

    Returns number

    pixel ratio

    Method

    _getPixelRatio

  • Gets the requested texture (an Image) via its path

    Parameters

    • render: IRender
    • imagePath: string

    Returns HTMLImageElement

    texture

    Method

    _getTexture

  • Returns the mean value of the given numbers.

    Parameters

    • values: number[]

    Returns number

    the mean of given values

    Method

    _mean

  • Updates render timing.

    Parameters

    • render: IRender
    • Optional time: number

    Returns void

    Method

    _updateTiming

  • Description

    Parameters

    • render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodies

  • Draws body angle indicators and axes

    Parameters

    • render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyAxes

  • Draws body bounds

    Parameters

    • render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyBounds

  • Optimised method for drawing body convex hull wireframes in one pass

    Parameters

    • _render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyConvexHulls

  • Draws body ids

    Parameters

    • _render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyIds

  • Draws body positions

    Parameters

    • render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyPositions

  • Draws body velocity

    Parameters

    • _render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyVelocity

  • Optimised method for drawing body wireframes in one pass

    Parameters

    • render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    bodyWireframes

  • Description

    Parameters

    • render: IRender
    • pairs: IPair[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    collisions

  • Description

    Parameters

    • constraints: IConstraint[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    constraints

  • Creates a new renderer. The options parameter is an object that specifies any properties you wish to override the defaults. All properties have default values, and many are pre-calculated automatically based on other properties. See the properties section below for detailed information on what you can pass via the options object.

    Parameters

    Returns IRender

    A new renderer

    Method

    create

  • Resets all transforms on the render context.

    Parameters

    Returns void

    Method

    endViewTransform

  • Description

    Parameters

    • inspector: IInspector
    • context: CanvasRenderingContext2D

    Returns void

    Method

    inspector

  • Positions and sizes the viewport around the given object bounds. Objects must have at least one of the following properties:

    • object.bounds
    • object.position
    • object.min and object.max
    • object.x and object.y

    Parameters

    • render: IRender
    • objects: any
    • padding: IVector = ...
    • center: boolean = true

    Returns void

    Method

    lookAt

  • Renders mouse position.

    Parameters

    • _render: IRender
    • mouse: IMouse
    • context: CanvasRenderingContext2D

    Returns void

    Method

    mousePosition

  • Renders engine and render performance information.

    Parameters

    • render: IRender
    • context: CanvasRenderingContext2D

    Returns void

    Method

    performance

  • Continuously updates the render canvas on the requestAnimationFrame event.

    Parameters

    Returns void

    Method

    run

  • Description

    Parameters

    • render: IRender
    • pairs: IPair[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    separations

  • Sets the pixel ratio of the renderer and updates the canvas. To automatically detect the correct ratio, pass the string 'auto' for pixelRatio.

    Parameters

    • render: IRender
    • pr: number | "auto"

    Returns void

    Method

    setPixelRatio

  • Sets the render width and height.

    Updates the canvas accounting for render.options.pixelRatio.

    Updates the bottom right render bound render.bounds.max relative to the provided width and height. The top left render bound render.bounds.min isn't changed.

    Follow this call with Render.lookAt if you need to change the render bounds.

    See also Render.setPixelRatio.

    Parameters

    • render: IRender
    • width: number

      The width (in CSS pixels)

    • height: number

      The height (in CSS pixels)

    Returns void

    Method

    setSize

  • Applies viewport transforms based on render.bounds to a render context.

    Parameters

    Returns void

    Method

    startViewTransform

  • Renders statistics about the engine and world useful for debugging.

    Parameters

    • render: IRender
    • context: CanvasRenderingContext2D
    • Optional _time: number

    Returns void

    Method

    stats

  • Renders a label, indicator and a chart.

    Parameters

    • context: CanvasRenderingContext2D
    • x: number
    • y: number
    • width: number
    • height: number
    • count: number
    • label: string
    • indicator: number
    • plotY: ((idx) => number)
        • (idx): number
        • Parameters

          • idx: number

          Returns number

    Returns void

    Method

    status

  • Ends execution of Render.run on the given render, by canceling the animation frame request event loop.

    Parameters

    Returns void

    Method

    stop

  • Renders body vertex numbers.

    Parameters

    • _render: IRender
    • bodies: IBody[]
    • context: CanvasRenderingContext2D

    Returns void

    Method

    vertexNumbers

  • Renders the given engine's Matter.World object. This is the entry point for all rendering and should be called every time the scene changes.

    Parameters

    • render: IRender
    • Optional _time: number

    Returns void

    Method

    world

Generated using TypeDoc