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, or a Canvas Element.

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


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

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

The Texture this TextureSource belongs to.

source HTMLImageElement | HTMLCanvasElement

The source image data.

width integer <optional>

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

height integer <optional>

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

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

Members


compressionAlgorithm :integer

Currently un-used.

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

<nullable> glTexture :WebGLTexture

The WebGL Texture of the source image.

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

height :integer

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:
  • integer
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 105)

image :HTMLImageElement|HTMLCanvasElement

The image data. This is either an Image element or a Canvas element.

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

isCanvas :boolean

Is the source image a Canvas Element?

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

isPowerOf2 :boolean

Are the source image dimensions a power of two?

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

isRenderTexture :boolean

Is the source image a Render Texture?

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

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 37)

resolution :number

The resolution of the source image.

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

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 115)

source :HTMLImageElement|HTMLCanvasElement|Phaser.GameObjects.RenderTexture

The source of the image data. This is either an Image Element, a Canvas Element or a RenderTexture.

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

texture :Phaser.Textures.Texture

The Texture this TextureSource belongs to.

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

width :integer

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:
  • integer
Since: 3.0.0
Source: src/textures/TextureSource.js (Line 95)

Methods


destroy()

Destroys this Texture Source and nulls the references.

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

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 165)

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 206)

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 226)