Phaser API Documentation

  Version: 
Filter

A Texture Source is the encapsulation of the actual source data for a Texture.

This is typically an Image Element, loaded from the file system or network, a Canvas Element or a Video Element.

A Texture can contain multiple Texture Sources, which only happens when a multi-atlas is loaded.

Constructor:

new TextureSource(texture, source, [width], [height], [flipY])

Parameters:

name type arguments Default description
texture Phaser.Textures.Texture

The Texture this TextureSource belongs to.

source HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Phaser.GameObjects.RenderTexture | Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper | Phaser.Textures.DynamicTexture | Phaser.Types.Textures.CompressedTextureData

The source image data.

width number <optional>

Optional width of the source image. If not given it's derived from the source itself.

height number <optional>

Optional height of the source image. If not given it's derived from the source itself.

flipY boolean <optional> false

Sets the UNPACK_FLIP_Y_WEBGL flag the WebGL Texture uses during upload.

Since: 3.0.0

Members

compressionAlgorithm: number
Focus
Focus

Description:

Holds the compressed textured algorithm, or null if it's not a compressed texture.

Prior to Phaser 3.60 this value always held null.

Type:
number
Default: null
Since: 3.0.0
Focus
Focus
flipY: boolean
Focus
Focus

Description:

Sets the UNPACK_FLIP_Y_WEBGL flag the WebGL Texture uses during upload.

Type:
boolean
Since: 3.20.0
Focus
Focus

Description:

The wrapped WebGL Texture of the source image. If this TextureSource is driven from a WebGLTexture already, then this wrapper contains a reference to that WebGLTexture.

Type:
Default: null
Since: 3.0.0
Focus
Focus
height: number
Focus
Focus

Description:

The height of the source image. If not specified in the constructor it will check the naturalHeight and then height properties of the source image.

Type:
number
Since: 3.0.0
Focus
Focus
image: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Uint8Array
Focus
Focus

Description:

The image data.

This is either an Image element, Canvas element, Video Element, or Uint8Array.

Type:
HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Uint8Array
Since: 3.0.0
Focus
Focus
isCanvas: boolean
Focus
Focus

Description:

Is the source image a Canvas Element?

Type:
boolean
Since: 3.0.0
Focus
Focus
isGLTexture: boolean
Focus
Focus

Description:

Is the source image a WebGLTextureWrapper?

Type:
boolean
Since: 3.19.0
Focus
Focus
isPowerOf2: boolean
Focus
Focus

Description:

Are the source image dimensions a power of two?

Type:
boolean
Since: 3.0.0
Focus
Focus
isRenderTexture: boolean
Focus
Focus

Description:

Is the source image a Render Texture?

Type:
boolean
Since: 3.12.0
Focus
Focus
isVideo: boolean
Focus
Focus

Description:

Is the source image a Video Element?

Type:
boolean
Since: 3.20.0
Focus
Focus
resolution: number
Focus
Focus

Description:

The resolution of the source image.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
scaleMode: number
Focus
Focus

Description:

The Scale Mode the image will use when rendering. Either Linear or Nearest.

Type:
number
Since: 3.0.0
Focus
Focus

Description:

The source of the image data.

This is either an Image Element, a Canvas Element, a Video Element, a RenderTexture or a WebGLTextureWrapper.

In Phaser 3.60 and above it can also be a Compressed Texture data object.

Type:
Since: 3.12.0
Focus
Focus

Description:

The Texture this TextureSource instance belongs to.

Type:
Since: 3.0.0
Focus
Focus
width: number
Focus
Focus

Description:

The width of the source image. If not specified in the constructor it will check the naturalWidth and then width properties of the source image.

Type:
number
Since: 3.0.0
Focus
Focus

Methods

destroy()
Focus
Focus

Description:

Destroys this Texture Source and nulls the references.

Since: 3.0.0
Focus
Focus
init(game)
Focus
Focus

Description:

Creates a WebGL Texture, if required, and sets the Texture filter mode.

Parameters:

name type description
game Phaser.Game

A reference to the Phaser Game instance.

Since: 3.0.0
Focus
Focus
setFilter(filterMode)
Focus
Focus

Description:

Sets the Filter Mode for this Texture.

The mode can be either Linear, the default, or Nearest.

For pixel-art you should use Nearest.

Parameters:

name type description
filterMode Phaser.Textures.FilterMode

The Filter Mode.

Since: 3.0.0
Focus
Focus
setFlipY([value])
Focus
Focus

Description:

Sets the UNPACK_FLIP_Y_WEBGL flag for the WebGL Texture during texture upload.

Parameters:

name type arguments Default description
value boolean <optional> true

Should the WebGL Texture be flipped on the Y axis on texture upload or not?

Since: 3.20.0
Focus
Focus
update()
Focus
Focus

Description:

If this TextureSource is backed by a Canvas and is running under WebGL, it updates the WebGLTexture using the canvas data.

Since: 3.7.0
Focus
Focus