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

Displacement

The Displacement Filter Controller.

This Filter controller manages the displacement effect.

The displacement effect is a visual technique that alters the position of pixels in an image

or texture based on the values of a displacement map. This effect is used to create the illusion

of depth, surface irregularities, or distortion in otherwise flat elements. It can be applied to

characters, objects, or backgrounds to enhance realism, convey movement, or achieve various

stylistic appearances.

A Displacement effect is added to a Camera via the FilterList component:


const camera = this.cameras.main;



camera.filters.internal.addDisplacement();

camera.filters.external.addDisplacement();

Constructor

new Displacement(camera, [texture], [x], [y])

Parameters

nametypeoptionaldefaultdescription
cameraPhaser.Cameras.Scene2D.CameraNoThe Camera that owns this filter.
texturestringYes"'__WHITE'"The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager.
xnumberYes0.005The amount of horizontal displacement to apply. A very small float number, such as 0.005.
ynumberYes0.005The amount of vertical displacement to apply. A very small float number, such as 0.005.

Scope: static

Extends

Phaser.Filters.Controller

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

Inherited Members

From Phaser.Filters.Controller:


Public Members

texture

texture: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

Description:

The underlying texture used for displacement.

Source: src/filters/Displacement.js#L76
Since: 4.0.0


x

x: number

Description:

The amount of horizontal displacement to apply.

The maximum horizontal displacement in pixels is x

multiplied by 0.5 times the width of the camera rendering the filter.

Source: src/filters/Displacement.js#L52
Since: 4.0.0


y

y: number

Description:

The amount of vertical displacement to apply.

The maximum vertical displacement in pixels is y

multiplied by 0.5 times the height of the camera rendering the filter.

Source: src/filters/Displacement.js#L64
Since: 4.0.0


Inherited Methods

From Phaser.Filters.Controller:


Public Methods

setTexture

<instance> setTexture([texture])

Description:

Sets the Texture to be used for the displacement effect.

You can only use a whole texture, not a frame from a texture atlas or sprite sheet.

Parameters:

nametypeoptionaldefaultdescription
texturestringYes"'__WHITE'"The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager.

Returns: Phaser.Filters.Displacement - This Filter Controller.

Source: src/filters/Displacement.js#L88
Since: 4.0.0