Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Textures . TextureSource

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Textures . TextureSource

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 | WebGLTexture | Phaser.GameObjects.RenderTexture

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:

Currently un-used.

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
glIndex: number
Focus
Focus

Description:

The current texture unit index as assigned by the WebGL Renderer. Un-used in canvas. Should be treated as read-only.

Type:
number
Default: 0
Since: 3.50.0
Focus
Focus
glIndexCounter: number
Focus
Focus

Description:

The counter value when this texture was last assigned an index by the WebGL Renderer. Un-used in canvas. Should be treated as read-only.

Type:
number
Default: -1
Since: 3.50.0
Focus
Focus
<nullable> glTexture: WebGLTexture
Focus
Focus

Description:

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

Type:
WebGLTexture
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
Focus
Focus

Description:

The image data.

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

Type:
HTMLImageElement | HTMLCanvasElement | HTMLVideoElement
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 WebGLTexture?

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
source: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | WebGLTexture | Phaser.GameObjects.RenderTexture
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 WebGLTexture.

Type:
HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | WebGLTexture | Phaser.GameObjects.RenderTexture
Since: 3.12.0
Focus
Focus

Description:

The Texture this TextureSource 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.

Examples:
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.

Examples:
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.

Examples:
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?

Examples:
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.

Examples:
Since: 3.7.0
Focus
Focus