- Matter.Render
- Methods
- Matter.Render._createCanvas
- Matter.Render._getPixelRatio
- Matter.Render._getTexture
- Matter.Render.applyBackground
- Matter.Render.bodies
- Matter.Render.bodyAxes
- Matter.Render.bodyBounds
- Matter.Render.bodyConvexHulls
- Matter.Render.bodyIds
- Matter.Render.bodyPositions
- Matter.Render.bodyShadows
- Matter.Render.bodyVelocity
- Matter.Render.bodyWireframes
- Matter.Render.collisions
- Matter.Render.constraints
- Matter.Render.create
- Matter.Render.debug
- Matter.Render.endViewTransform
- Matter.Render.grid
- Matter.Render.inspector
- Matter.Render.lookAt
- Matter.Render.mousePosition
- Matter.Render.run
- Matter.Render.separations
- Matter.Render.setPixelRatio
- Matter.Render.startViewTransform
- Matter.Render.stop
- Matter.Render.vertexNumbers
- Matter.Render.world
- Item Index
- Properties
- Events
- Methods
Matter.Render
Defined in: src/render/Render.js:1
The Matter.Render
module is a simple HTML5 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.
Methods
Matter.Render._createCanvas
(width, height)
→ private
Description
Parameters
width
Object
height
Object
Returns
canvas
Matter.Render._getPixelRatio
(canvas)
→ Numberprivate
Gets the pixel ratio of the canvas.
Parameters
canvas
HTMLElement
Returns
Numberpixel ratio
Matter.Render._getTexture
(render, imagePath)
→ Imageprivate
Gets the requested texture (an Image) via its path
Parameters
render
Render
imagePath
String
Returns
Imagetexture
Matter.Render.applyBackground
(render, background)
private
Applies the background to the canvas using CSS.
Parameters
render
Render
background
String
Matter.Render.bodies
(render, bodies, context)
private
Description
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyAxes
(render, bodies, context)
private
Draws body angle indicators and axes
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyBounds
(render, bodies, context)
private
Draws body bounds
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyConvexHulls
(render, bodies, context)
private
Optimised method for drawing body convex hull wireframes in one pass
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyIds
(render, bodies, context)
private
Draws body ids
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyPositions
(render, bodies, context)
private
Draws body positions
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyShadows
(render, bodies, context)
private
Description
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyVelocity
(render, bodies, context)
private
Draws body velocity
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.bodyWireframes
(render, bodies, context)
private
Optimised method for drawing body wireframes in one pass
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.collisions
(render, pairs, context)
private
Description
Parameters
render
Render
pairs
Pair[]
context
RenderingContext
Matter.Render.constraints
(constraints, context)
private
Description
Parameters
constraints
Constraint[]
context
RenderingContext
Matter.Render.create
([options])
→ Render
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
[options]
Objectoptional
Returns
RenderA new renderer
Matter.Render.debug
(render, context)
private
Description
Parameters
render
Render
context
RenderingContext
Matter.Render.endViewTransform
(render)
Resets all transforms on the render context.
Parameters
render
Render
Matter.Render.grid
(render, grid, context)
private
Description
Parameters
render
Render
grid
Grid
context
RenderingContext
Matter.Render.inspector
(inspector, context)
private
Description
Parameters
inspector
Inspector
context
RenderingContext
Matter.Render.lookAt
(render, objects, [padding], [center=true])
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
andobject.max
object.x
andobject.y
Parameters
render
Render
objects
Object[]
[padding]
Vectoroptional
[center=true]
Booloptional
Matter.Render.mousePosition
(render, mouse, context)
private
Renders mouse position.
Parameters
render
Render
mouse
Mouse
context
RenderingContext
Matter.Render.run
(render)
Continuously updates the render canvas on the requestAnimationFrame
event.
Parameters
render
Render
Matter.Render.separations
(render, pairs, context)
private
Description
Parameters
render
Render
pairs
Pair[]
context
RenderingContext
Matter.Render.setPixelRatio
(render, pixelRatio)
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
Render
pixelRatio
Number
Matter.Render.startViewTransform
(render)
Applies viewport transforms based on render.bounds
to a render context.
Parameters
render
Render
Matter.Render.stop
(render)
Ends execution of Render.run
on the given render
, by canceling the animation frame request event loop.
Parameters
render
Render
Matter.Render.vertexNumbers
(render, bodies, context)
private
Renders body vertex numbers.
Parameters
render
Render
bodies
Body[]
context
RenderingContext
Matter.Render.world
(render)
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
Render
Item Index
Methods
- _createCanvas
- _getPixelRatio
- _getTexture
- applyBackground
- bodies
- bodyAxes
- bodyBounds
- bodyConvexHulls
- bodyIds
- bodyPositions
- bodyShadows
- bodyVelocity
- bodyWireframes
- collisions
- constraints
- create
- debug
- endViewTransform
- grid
- inspector
- lookAt
- mousePosition
- run
- separations
- setPixelRatio
- startViewTransform
- stop
- vertexNumbers
- world
Properties
The following properties are specified for objects created by <span class="prefix">Matter.</span>.create
and for objects passed to it via the options
argument.
- bounds
- canvas
- context
- controller
- element
- engine
- options
- options.hasBounds
- options.height
- options.width
- textures
Events
Properties
The following properties are specified for objects created by Matter.Render.create
and for objects passed to it via the options
argument.
Render.bounds
A Bounds
object that specifies the drawing view region. Rendering will be automatically transformed and scaled to fit within the canvas size (render.options.width
and render.options.height
). This allows for creating views that can pan or zoom around the scene. You must also set render.options.hasBounds
to true
to enable bounded rendering.
Render.canvas
The canvas element to render to. If not specified, one will be created if render.element
has been specified.
Default: null
Render.context
The 2d rendering context from the render.canvas
element.
Render.controller
A back-reference to the Matter.Render
module.
Render.element
A reference to the element where the canvas is to be inserted (if render.canvas
has not been specified)
Default: null
Render.engine
A reference to the Matter.Engine
instance to be used.
Render.options
The configuration options of the renderer.
Render.options.hasBounds
A flag that specifies if render.bounds
should be used when rendering.
Default: false
Render.options.height
The target height in pixels of the render.canvas
to be created.
Default: 600
Render.options.width
The target width in pixels of the render.canvas
to be created.
Default: 800
Render.textures
The sprite texture cache.
Events
The following events are emitted by objects created by <span class="prefix">Matter.</span>Render.create
to objects that have subscribed using Matter.Events.on
.
Events.on(Render, "afterRender", callback)
Fired after rendering
Event Payload:
event
Object
An event object
timestamp
Number
The engine.timing.timestamp of the event
source
The source object of the event
name
The name of the event
Events.on(Render, "beforeRender", callback)
Fired before rendering
Event Payload:
event
Object
An event object
timestamp
Number
The engine.timing.timestamp of the event
source
The source object of the event
name
The name of the event