Class: BaseTexture

PIXI. BaseTexture

A texture stores the information that represents an image. All textures have a base texture.

new PIXI.BaseTexture(source, scaleMode, resolution)

Name Type Default Description
source HTMLImageElement | HTMLCanvasElement optional

the source object of the texture.

scaleMode number PIXI.SCALE_MODES.DEFAULT optional

See PIXI.SCALE_MODES for possible values

resolution number 1 optional

The resolution / device pixel ratio of the texture

Extends

  • EventEmitter

Methods

staticPIXI.BaseTexture.fromCanvas(canvas, scaleMode){PIXI.BaseTexture}

Helper function that creates a base texture from the given canvas element.

Name Type Description
canvas HTMLCanvasElement

The canvas element source of the texture

scaleMode number

See PIXI.SCALE_MODES for possible values

Returns:
Type Description
PIXI.BaseTexture The new base texture.

staticPIXI.BaseTexture.fromImage(imageUrl, crossorigin, scaleMode, sourceScale){PIXI.BaseTexture}

Helper function that creates a base texture from the given image url.
If the image is not in the base texture cache it will be created and loaded.

Name Type Default Description
imageUrl string

The image url of the texture

crossorigin boolean (auto) optional

Should use anonymous CORS? Defaults to true if the URL is not a data-URI.

scaleMode number PIXI.SCALE_MODES.DEFAULT optional

See PIXI.SCALE_MODES for possible values

sourceScale number (auto) optional

Scale for the original image, used with Svg images.

Returns:
Type Description
PIXI.BaseTexture The new base texture.

Checks if source is an SVG image and whether it's loaded via a URL or a data URI. Then calls
_loadSvgSourceUsingDataUri or _loadSvgSourceUsingXhr.

_loadSvgSourceUsingDataUri(dataUri)

Reads an SVG string from data URI and then calls _loadSvgSourceUsingString.

Name Type Description
dataUri string

The data uri to load from.

_loadSvgSourceUsingString(svgString)

Loads texture using an SVG string. The original SVG Image is stored as origSource and the
created canvas is the new source. The SVG is scaled using sourceScale. Called by
_loadSvgSourceUsingXhr or _loadSvgSourceUsingDataUri.

Name Type Description
svgString string

SVG source as string

Fires:
  • event:loaded

_loadSvgSourceUsingXhr()

Loads an SVG string from imageUrl using XHR and then calls _loadSvgSourceUsingString.

Updates type of the source image.

Destroys this base texture

Frees the texture from WebGL memory without destroying this texture object.
This means you can still use the texture later which will upload it to GPU
memory again.

protectedloadSource(source)

Load a source.

If the source is not-immediately-available, such as an image that needs to be
downloaded, then the 'loaded' or 'error' event will be dispatched in the future
and hasLoaded will remain false after this call.

The logic state after calling loadSource directly or indirectly (eg. fromImage, new BaseTexture) is:

if (texture.hasLoaded) {
   // texture ready for use
} else if (texture.isLoading) {
   // listen to 'loaded' and/or 'error' events on texture
} else {
   // not loading, not going to load UNLESS the source is reloaded
   // (it may still make sense to listen to the events)
}
Name Type Description
source HTMLImageElement | HTMLCanvasElement

the source object of the texture.

Updates the texture on all the webgl renderers, this also assumes the src has changed.

Fires:
  • event:update

updateSourceImage(newSrc)

Changes the source image of the texture.
The original source must be an Image element.

Name Type Description
newSrc string

the path of the image

Events

Fired when a not-immediately-available source fails to load.

Fired when a not-immediately-available source finishes loading.