Skip to main content
Version: Phaser v4.0.0

Noise

A Noise Game Object.

This game object is a quad which displays random noise. You can manipulate this object like any other, make it interactive, and use it in filters and masks to create visually stunning effects.

Behind the scenes, a Noise is a Phaser.GameObjects.Shader using a specific shader program.

Noise or 'white noise' is simply random values. These are created by hashing the offset pixel coordinates, so the same noise is always created at the same position. This creates a reproducible effect.

You can set the color and transparency of the noise.

You can scroll the noise by animating the noiseOffset property. Note that floating-point precision is very important to this effect. Scrolling very large distances may cause blockiness in the output. Scrolling very small distances may cause the output to change completely, as it is not processing the same exact values. If you scroll by an exact fraction of the resolution of the object, the output will remain mostly the same, but it is not guaranteed to be stable. It's more effective to use setRenderToTexture and use this as a texture in a TileSprite.

You can set noisePower to sculpt the output levels. Higher power reduces higher values. Lower power reduces lower values.

Constructor

new Noise(scene, [config], [x], [y], [width], [height])

Parameters

nametypeoptionaldefaultdescription
scenePhaser.SceneNoThe Scene to which this Game Object belongs.
configPhaser.Types.GameObjects.Noise.NoiseQuadConfigYesThe configuration for this Game Object.
xnumberYes0The horizontal position of this Game Object in the world.
ynumberYes0The vertical position of this Game Object in the world.
widthnumberYes128The width of the Game Object.
heightnumberYes128The height of the Game Object.

Scope: static

Extends

Phaser.GameObjects.Shader

Source: src/gameobjects/noise/Noise.js#L12
Since: 4.0.0

Inherited Members

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.ComputedSize:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shader:


Public Members

noiseColorEnd

noiseColorEnd: Phaser.Display.Color

Description:

The color mapped to high noise values (approaching 1).

The default is white. You can set any color, and change the alpha.

Source: src/gameobjects/noise/Noise.js#L114
Since: 4.0.0


noiseColorStart

noiseColorStart: Phaser.Display.Color

Description:

The color mapped to low noise values (approaching 0).

The default is black. You can set any color, and change the alpha.

Source: src/gameobjects/noise/Noise.js#L103
Since: 4.0.0


noiseOffset

noiseOffset: Array.<number>

Description:

The offset of the noise in each dimension: [ x, y ]. Animate x and y to scroll the noise pattern.

This must be an array of 2 numbers.

Source: src/gameobjects/noise/Noise.js#L75
Since: 4.0.0


noisePower

noisePower: number

Description:

The power to apply to the noise value. This can enhance/suppress high/low noise.

Source: src/gameobjects/noise/Noise.js#L92
Since: 4.0.0


noiseRandomChannels

noiseRandomChannels: boolean

Description:

Whether to render channel noise separately, creating many colors of output.

Source: src/gameobjects/noise/Noise.js#L130
Since: 4.0.0


noiseRandomNormal

noiseRandomNormal: boolean

Description:

Whether to render a random normal value per pixel. The normal is in the hemisphere facing the camera.

This value overrides noiseRandomChannels.

Source: src/gameobjects/noise/Noise.js#L141
Since: 4.0.0


Inherited Methods

From Phaser.Events.EventEmitter:

From Phaser.GameObjects.Components.BlendMode:

From Phaser.GameObjects.Components.ComputedSize:

From Phaser.GameObjects.Components.Depth:

From Phaser.GameObjects.Components.Filters:

From Phaser.GameObjects.Components.GetBounds:

From Phaser.GameObjects.Components.Origin:

From Phaser.GameObjects.Components.RenderSteps:

From Phaser.GameObjects.Components.ScrollFactor:

From Phaser.GameObjects.Components.Transform:

From Phaser.GameObjects.Components.Visible:

From Phaser.GameObjects.GameObject:

From Phaser.GameObjects.Shader:


Public Methods

setNoiseColor

<instance> setNoiseColor([start], [end])

Description:

Set the colors of the noise, from a variety of color formats.

  • A number is expected to be a 24 or 32 bit RGB or ARGB value.

  • A string is expected to be a hex code.

  • An array of numbers is expected to be RGB or RGBA in the range 0-1.

  • A Color object can be used.

Parameters:

nametypeoptionaldefaultdescription
startnumber | stringArray.<number>Phaser.Display.ColorYes
endnumber | stringArray.<number>Phaser.Display.ColorYes

Returns: Phaser.GameObjects.Noise - This game object.

Source: src/gameobjects/noise/Noise.js#L155
Since: 4.0.0