Class: BaseTexture

PIXI.BaseTexture

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

new PIXI.BaseTexture (resource, options)

Name Type Default Description
resource PIXI.resources.Resource | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement null optional

The current resource to use, for things that aren't Resource objects, will be converted into a Resource.

options Object optional

Collection of options

Name Type Default Description
mipmap boolean PIXI.settings.MIPMAP_TEXTURES optional

If mipmapping is enabled for texture

wrapMode PIXI.WRAP_MODES PIXI.settings.WRAP_MODE optional

Wrap mode for textures

scaleMode PIXI.SCALE_MODES PIXI.settings.SCALE_MODE optional

Default scale mode, linear, nearest

format PIXI.FORMATS PIXI.FORMATS.RGBA optional

GL format type

type PIXI.TYPES PIXI.TYPES.UNSIGNED_BYTE optional

GL data type

target PIXI.TARGETS PIXI.TARGETS.TEXTURE_2D optional

GL texture target

premultiplyAlpha boolean true optional

Pre multiply the image alpha

width number 0 optional

Width of the texture

height number 0 optional

Height of the texture

resourceOptions object optional

Optional resource options, see autoDetectResource

Extends

Members

cacheId string

Currently default cache ID.

destroyed boolean readonly

Flag if BaseTexture has been destroyed.

format PIXI.FORMATS

The pixel format of the texture

Default Value:
  • PIXI.FORMATS.RGBA

height number readonly

The height of the base texture set when the image has loaded

isPowerOfTwo boolean readonly

Whether or not the texture is a power of two, try to use power of two textures as much as you can

Default Value:
  • false

mipmap boolean

If mipmapping was used for this texture, enable and disable with enableMipmap()

premultiplyAlpha boolean

Set to true to enable pre-multiplied alpha

Default Value:
  • true

realHeight number readonly

Pixel height of the source of this texture

realWidth number readonly

Pixel width of the source of this texture

resolution number

The resolution / device pixel ratio of the texture

Default Value:
  • PIXI.settings.RESOLUTION

resource PIXI.resources.Resource readonly

The resource used by this BaseTexture, there can only be one resource per BaseTexture, but textures can share resources.

scaleMode number

The scale mode to apply when scaling this texture

Default Value:
  • PIXI.settings.SCALE_MODE
See:

target PIXI.TARGETS

The target type

Default Value:
  • PIXI.TARGETS.TEXTURE_2D

textureCacheIds Array.<string> readonly

The collection of alternative cache ids, since some BaseTextures can have more than one ID, short name and longer full URL

type PIXI.TYPES

The type of resource data

Default Value:
  • PIXI.TYPES.UNSIGNED_BYTE

valid boolean readonly

Generally speaking means when resource is loaded.

width number readonly

The width of the base texture set when the image has loaded

wrapMode number

How the texture wraps

Methods

PIXI.BaseTexture.addToCache (baseTexture, id) static

Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object.

Name Type Description
baseTexture PIXI.BaseTexture

The BaseTexture to add to the cache.

id string

The id that the BaseTexture will be stored against.

PIXI.BaseTexture.from (source, options)PIXI.BaseTexture static

Helper function that creates a base texture based on the source you provide. The source can be - image url, image element, canvas element. If the source is an image url or an image element and not in the base texture cache, it will be created and loaded.

Name Type Description
source string | HTMLImageElement | HTMLCanvasElement | SVGElement | HTMLVideoElement

The source to create base texture from.

options object optional

See PIXI.BaseTexture's constructor for options.

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

PIXI.BaseTexture.fromBuffer (buffer, width, height, options)PIXI.BaseTexture static

Create a new BaseTexture with a BufferResource from a Float32Array. RGBA values are floats from 0 to 1.

Name Type Description
buffer Float32Array | UintArray

The optional array to use, if no data is provided, a new Float32Array is created.

width number

Width of the resource

height number

Height of the resource

options object optional

See PIXI.BaseTexture's constructor for options.

Returns:
Type Description
PIXI.BaseTexture The resulting new BaseTexture

PIXI.BaseTexture.fromCanvas () Deprecated : since 5.0.0 static

See:

PIXI.BaseTexture.fromImage () Deprecated : since 5.0.0 static

See:

PIXI.BaseTexture.fromSVG () Deprecated : since 5.0.0 static

See:

PIXI.BaseTexture.removeFromCache (baseTexture)PIXI.BaseTexture | null static

Remove a BaseTexture from the global BaseTextureCache.

Name Type Description
baseTexture string | PIXI.BaseTexture

id of a BaseTexture to be removed, or a BaseTexture instance itself.

Returns:
Type Description
PIXI.BaseTexture | null The BaseTexture that was removed.

destroy ()

Destroys this base texture. The method stops if resource doesn't want this texture to be destroyed. Removes texture from all caches.

dispose ()

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.

Fires:
  • PIXI.BaseTexture#event:dispose

getDrawableSource ()CanvasImageSource

Get the drawable source, such as HTMLCanvasElement or HTMLImageElement suitable for rendering with CanvasRenderer. Provided by @pixi/canvas-renderer package.

Returns:
Type Description
CanvasImageSource Source to render with CanvasRenderer

setRealSize (realWidth, realHeight, resolution)BaseTexture

Sets real size of baseTexture, preserves current resolution.

Name Type Description
realWidth number

Full rendered width

realHeight number

Full rendered height

resolution number optional

Optionally set resolution

Returns:
Type Description
BaseTexture this

setResolution (resolution)BaseTexture

Changes resolution

Name Type Description
resolution number optional

res

Returns:
Type Description
BaseTexture this

setResource (resource)BaseTexture

Sets the resource if it wasnt set. Throws error if resource already present

Name Type Description
resource PIXI.resources.Resource

that is managing this BaseTexture

Returns:
Type Description
BaseTexture this

setSize (width, height, resolution)BaseTexture

Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.

Name Type Description
width number

Visual width

height number

Visual height

resolution number optional

Optionally set resolution

Returns:
Type Description
BaseTexture this

setStyle (options, scaleMode, mipmap)BaseTexture

Changes style options of BaseTexture

Name Type Description
options object
scaleMode PIXI.SCALE_MODES optional

pixi scalemode

mipmap boolean optional

enable mipmaps

Returns:
Type Description
BaseTexture this

update ()

Invalidates the object. Texture becomes valid if width and height are greater than zero.