Class: Filter

Phaser. Filter

new Filter(game [, uniforms] [, fragmentSrc])

This is a base Filter class to use for any Phaser filter development. If you want to make a custom filter, this should be your base class.

The default uniforms, types and values for all Filters are:

resolution: { type: '2f', value: { x: 256, y: 256 }}
time: { type: '1f', value: 0 }
mouse: { type: '2f', value: { x: 0.0, y: 0.0 } }
date: { type: '4fv', value: [ d.getFullYear(),  d.getMonth(),  d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] }
sampleRate: { type: '1f', value: 44100.0 }
iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } }
iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } }
iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } }
iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } }

The vast majority of filters (including all of those that ship with Phaser) use fragment shaders, and therefore only work in WebGL and are not supported by Canvas at all.

Parameters:
Name Type Argument Description
game Phaser.Game

A reference to the currently running game.

uniforms object <optional>

Uniform mappings object. The uniforms are added on the default uniforms, or replace them if the keys are the same.

fragmentSrc Array | string <optional>

The fragment shader code. Either an array, one element per line of code, or a string.

Source:
src/core/Filter.js line 35

Members

dirty : boolean

Internal PIXI var.

Type:
  • boolean
Default Value:
  • true
Source:
src/core/Filter.js line 66

fragmentSrc : array | string

The fragment shader code.

Type:
  • array | string
Source:
src/core/Filter.js line 120

game : Phaser.Game

A reference to the currently running game.

Type:
Source:
src/core/Filter.js line 40

height : number

The height (resolution uniform)

Type:
  • number
Source:
src/core/Filter.js line 278

padding : number

Internal PIXI var.

Type:
  • number
Source:
src/core/Filter.js line 72

prevPoint : Phaser.Point

The previous position of the pointer (we don't update the uniform if the same)

Type:
Source:
src/core/Filter.js line 77

type : number

The const type of this object, either Phaser.WEBGL_FILTER or Phaser.CANVAS_FILTER.

Type:
  • number
Source:
src/core/Filter.js line 46

uniforms : object

Default uniform mappings. Compatible with ShaderToy and GLSLSandbox.

Type:
  • object
Source:
src/core/Filter.js line 88

width : number

The width (resolution uniform)

Type:
  • number
Source:
src/core/Filter.js line 260

Methods

addToWorld( [x] [, y] [, width] [, height] [, anchorX] [, anchorY])

Creates a new Phaser.Image object using a blank texture and assigns this Filter to it. The image is then added to the world.

If you don't provide width and height values then Filter.width and Filter.height are used.

If you do provide width and height values then this filter will be resized to match those values.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The x coordinate to place the Image at.

y number <optional>
0

The y coordinate to place the Image at.

width number <optional>

The width of the Image. If not specified (or null) it will use Filter.width. If specified Filter.width will be set to this value.

height number <optional>

The height of the Image. If not specified (or null) it will use Filter.height. If specified Filter.height will be set to this value.

anchorX number <optional>
0

Set the x anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right.

anchorY number <optional>
0

Set the y anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right.

Source:
src/core/Filter.js line 174
Returns:

The newly added Image object.

Type
Phaser.Image

destroy()

Clear down this Filter and null out references to game.

Source:
src/core/Filter.js line 240

init()

This should be over-ridden. Will receive a variable number of arguments.

Source:
src/core/Filter.js line 125

setResolution(width, height)

Set the resolution uniforms on the filter.

Parameters:
Name Type Description
width number

The width of the display.

height number

The height of the display.

Source:
src/core/Filter.js line 137

syncUniforms()

Syncs the uniforms between the class object and the shaders.

Source:
src/core/Filter.js line 227

update( [pointer])

Updates the filter.

Parameters:
Name Type Argument Description
pointer Phaser.Pointer <optional>

A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.

Source:
src/core/Filter.js line 150

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.