module:OffscreenCanvas

module:OffscreenCanvas

Off-screen canvas class

Constructor

# new module:OffscreenCanvas(widthopt, heightopt, optionsopt)

Off-screen canvas constructor

Parameters:
Name Type Attributes Default Description
width Number <optional>
1

Width of the canvas

height Number <optional>
1

Height of the canvas

options ContainerOptions <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:
Name Type Default Description
width Number 1

Width of the canvas

height Number 1

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:
Name Type Attributes Description
vectorDefinition VectorDefinition <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:
Name Type Attributes Description
imageData ImageData

Data to add to the canvas

positionDefinition PositionDefinition <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:
Name Type Description
enable Boolean

Should the smoothing be active or not

Returns:

Itself

Type
OffScreenCanvas

# toImage(vectorDefinitionopt, typeopt) → {HTMLImageElement}

Return an image composed of its content

Parameters:
Name Type Attributes Default Description
vectorDefinition VectorDefinition <optional>

Box to restrict exported data

type String <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
Name Type Attributes Default Description
fill String | Color <optional>
null

Background color

opacity Number <optional>
1

Global opacity