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
| name | type | optional | default | description |
|---|---|---|---|---|
| camera | Phaser.Cameras.Scene2D.Camera | No | The Camera that owns this filter. | |
| texture | string | Yes | "'__WHITE'" | The unique string-based key of the texture to use for displacement, which must exist in the Texture Manager. |
| x | number | Yes | 0.005 | The amount of horizontal displacement to apply. A very small float number, such as 0.005. |
| y | number | Yes | 0.005 | The amount of vertical displacement to apply. A very small float number, such as 0.005. |
Scope: static
Extends
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:
| name | type | optional | default | description |
|---|---|---|---|---|
| texture | string | Yes | "'__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