You’re reading the docs for Phaser v4.0.0. The latest is Phaser v4.1.0.

Sampler

Phaser.Filters.Sampler

The Sampler Filter Controller.

This controller reads pixel data from the camera's rendered output and passes it to a user-defined callback. Unlike other filter controllers, the Sampler does not alter the rendered image in any way — it is purely a data extraction tool. It can sample a single point, a rectangular region, or the entire camera view, and is useful for techniques such as color picking, pixel-perfect hit detection, or runtime visual analysis.

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 invoke once the pixel data has been read from the sampled region. It receives the snapshot result, which may be an HTMLImageElement (for region snapshots) or a Phaser.Display.Color (for point snapshots), depending on the region type.

Source: src/filters/Sampler.js#L52
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#L64
Since: 4.0.0


Inherited Methods

From Phaser.Filters.Controller: