module:OffscreenCanvas

Off-screen canvas class

Constructor

new module:OffscreenCanvas(widthopt, heightopt, optionsopt)

Off-screen canvas constructor

Parameters:
NameTypeAttributesDefaultDescription
widthNumber<optional>
1

Width of the canvas

heightNumber<optional>
1

Height of the canvas

optionsContainerOptions<optional>

Specific options

Members

(static) defaultOptions :OffscreenCanvasOptions

Type:
  • OffscreenCanvasOptions

center

Return this scene center point

ctx :CanvasRenderingContext2D

Type:
  • CanvasRenderingContext2D

height

height

size

Return the whole scene size

width

width

Methods

(static) getDrawingContext(width, height) → {CanvasRenderingContext2D}

Build a canvas context and returns it

Parameters:
NameTypeDefaultDescription
widthNumber1

Width of the canvas

heightNumber1

Height of the canvas

Returns:
Type: 
CanvasRenderingContext2D

clear() → {OffScreenCanvas}

Erase the canvas

Returns:

Itself

Type: 
OffScreenCanvas

getImageData(vectorDefinitionopt) → {ImageData}

Return the whole canvas as data

Parameters:
NameTypeAttributesDescription
vectorDefinitionVectorDefinition<optional>

Box of data to extract

Returns:
Type: 
ImageData

getRandomPosition() → {Position}

Return a random position within the scene

Returns:
Type: 
Position

render() → {OffScreenCanvas}

Render a container and its children into the canvas

Returns:

Itself

Type: 
OffScreenCanvas

setImageData(imageData, positionDefinitionopt)

Put data into the canvas

Parameters:
NameTypeAttributesDescription
imageDataImageData

Data to add to the canvas

positionDefinitionPositionDefinition<optional>

Position of the data

setImageSmoothing(enable) → {OffScreenCanvas}

Change the behavior for upscaled images, smoothing is good for pictures but bad for pixel-art

Parameters:
NameTypeDescription
enableBoolean

Should the smoothing be active or not

Returns:

Itself

Type: 
OffScreenCanvas

toImage(vectorDefinitionopt, typeopt) → {HTMLImageElement}

Return an image composed of its content

Parameters:
NameTypeAttributesDefaultDescription
vectorDefinitionVectorDefinition<optional>

Box to restrict exported data

typeString<optional>
"image/png"

Data format. Supported format depend on the browser implementation (png or jpeg are the only safe choices)

Returns:
Type: 
HTMLImageElement

Type Definitions

OffscreenCanvasOptions

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
fillString | Color<optional>
null

Background color

opacityNumber<optional>
1

Global opacity