Class: TextureSource

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.


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

Parameters:
Name Type Argument Default Description
texture Phaser.Textures.Texture

The Texture this TextureSource belongs to.

source HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Phaser.GameObjects.RenderTexture | WebGLTexture

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
Source: src/textures/TextureSource.js (Line 12)

Members


compressionAlgorithm :number

Currently un-used.

Type:
  • number
Since: 3.0.0
Default Value:
  • null
Source: src/textures/TextureSource.js (Line 81)

flipY :boolean

Sets the UNPACK_FLIP_Y_WEBGL flag the WebGL Texture uses during upload.

Type:
  • boolean
Since: 3.20.0
Source: src/textures/TextureSource.js (Line 209)

glIndex :number

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

Type:
  • number
Since: 3.50.0
Default Value:
  • 0
Source: src/textures/TextureSource.js (Line 187)

glIndexCounter :number

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
Since: 3.50.0
Default Value:
  • -1
Source: src/textures/TextureSource.js (Line 198)

<nullable> glTexture :WebGLTexture

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
Since: 3.0.0
Default Value:
  • null
Source: src/textures/TextureSource.js (Line 176)

height :number

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
Source: src/textures/TextureSource.js (Line 111)

image :HTMLImageElement|HTMLCanvasElement|HTMLVideoElement

The image data.

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

Type:
  • HTMLImageElement | HTMLCanvasElement | HTMLVideoElement
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 70)

isCanvas :boolean

Is the source image a Canvas Element?

Type:
  • boolean
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 131)

isGLTexture :boolean

Is the source image a WebGLTexture?

Type:
  • boolean
Since: 3.19.0
Source: src/textures/TextureSource.js (Line 158)

isPowerOf2 :boolean

Are the source image dimensions a power of two?

Type:
  • boolean
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 167)

isRenderTexture :boolean

Is the source image a Render Texture?

Type:
  • boolean
Since: 3.12.0
Source: src/textures/TextureSource.js (Line 149)

isVideo :boolean

Is the source image a Video Element?

Type:
  • boolean
Since: 3.20.0
Source: src/textures/TextureSource.js (Line 140)

renderer :Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer

The Texture this TextureSource belongs to.

Type:
Since: 3.7.0
Source: src/textures/TextureSource.js (Line 41)

resolution :number

The resolution of the source image.

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/textures/TextureSource.js (Line 91)

scaleMode :number

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

Type:
  • number
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 121)

source :HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|Phaser.GameObjects.RenderTexture|WebGLTexture

The source of the image data.

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

Type:
Since: 3.12.0
Source: src/textures/TextureSource.js (Line 59)

texture :Phaser.Textures.Texture

The Texture this TextureSource belongs to.

Type:
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 50)

width :number

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
Source: src/textures/TextureSource.js (Line 101)

Methods


destroy()

Destroys this Texture Source and nulls the references.

Since: 3.0.0
Source: src/textures/TextureSource.js (Line 332)

init(game)

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
Source: src/textures/TextureSource.js (Line 221)

setFilter(filterMode)

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
Source: src/textures/TextureSource.js (Line 272)

setFlipY( [value])

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

Parameters:
Name Type Argument 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
Source: src/textures/TextureSource.js (Line 294)

update()

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
Source: src/textures/TextureSource.js (Line 311)