Skip to main content
Version: Phaser v4.0.0-rc.6

Sampler

The Sampler Filter Controller.

This controller manages a sampler.

It doesn't actually render anything, and leaves the image unaltered.

It is used to sample a region of the camera view, and pass the results to a callback.

This is useful for extracting data from the camera view.

This operation is expensive, so use sparingly.

A Sampler is added to a Camera via the FilterList component:


const camera = this.cameras.main;



camera.filters.internal.addSampler(callback, region);

camera.filters.external.addSampler(callback, region);

Constructor

new Sampler(camera, callback, [region])

Parameters

nametypeoptionaldefaultdescription
cameraPhaser.Cameras.Scene2D.CameraNoThe Camera that owns this filter.
callbackPhaser.Types.Renderer.Snapshot.SnapshotCallbackNoThe callback to call with the results of the sampler.
regionnull | Phaser.Types.Math.Vector2LikePhaser.Geom.RectangleYesnull

Scope: static

Extends

Phaser.Filters.Controller

Source: src/filters/Sampler.js#L10
Since: 4.0.0

Inherited Members

From Phaser.Filters.Controller:


Public Members

callback

callback: Phaser.Types.Renderer.Snapshot.SnapshotCallback

Description:

The callback to call with the results of the sampler.

Source: src/filters/Sampler.js#L50
Since: 4.0.0


region

region: null, Phaser.Types.Math.Vector2Like, Phaser.Geom.Rectangle

Description:

The region to sample. If null, the entire camera view is sampled.

If a Phaser.Types.Math.Vector2Like, a point is sampled.

If a Phaser.Geom.Rectangle, the region is sampled.

Source: src/filters/Sampler.js#L59


Inherited Methods

From Phaser.Filters.Controller: