Class: BaseTexture

PIXI.BaseTexture

A Texture stores the information that represents an image. All textures have a base texture, which contains information about the source. Therefore you can have many textures all using a single BaseTexture

Extends

Members

PIXI.BaseTexture._globalBatch number static

Global number of the texture batch, used by multi-texture renderers

_batchEnabled number

Number of the texture batch, used by multi-texture renderers

_batchLocation number

Location inside texture batch, used by multi-texture renderers

_id number Deprecated : since 5.2.0

Batch local field, stores current texture location

See:
  • PIXI.BaseTexture#_batchLocation

alphaMode PIXI.ALPHA_MODES

How to treat premultiplied alpha, see PIXI.ALPHA_MODES.

Default Value:
  • PIXI.ALPHA_MODES.UNPACK

anisotropicLevel number

Anisotropic filtering level of texture

Default Value:
  • PIXI.settings.ANISOTROPIC_LEVEL

cacheId string

Currently default cache ID.

destroyed boolean

Flag if BaseTexture has been destroyed.

dirtyId number

Used by TextureSystem to only update texture to the GPU when needed. Please call update() to increment it.

format PIXI.FORMATS

The pixel format of the texture

Default Value:
  • PIXI.FORMATS.RGBA

hasLoaded boolean Deprecated : since 5.0.0

See:
  • PIXI.BaseTexture#valid

height number

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

imageUrl string Deprecated : since 5.0.0

See:
  • PIXI.ImageResource#url

isPowerOfTwo boolean

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 mode of the texture, affects downscaled images

Default Value:
  • PIXI.settings.MIPMAP_TEXTURES

parentTextureArray PIXI.BaseTexture

Whether its a part of another texture, handled by ArrayResource or CubeResource

premultiplyAlpha boolean Deprecated : since 5.2.0

See:
  • PIXI.BaseTexture#alphaMode

realHeight number

Pixel height of the source of this texture

realWidth number

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.Resource

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

scaleMode PIXI.SCALE_MODES

The scale mode to apply when scaling this texture

Default Value:
  • PIXI.settings.SCALE_MODE

source HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | SVGElement Deprecated : since 5.0.0

See:
  • PIXI.BaseImageResource#source

target PIXI.TARGETS

The target type

Default Value:
  • PIXI.TARGETS.TEXTURE_2D

textureCacheIds Array

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

Generally speaking means when resource is loaded.

width number

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

wrapMode number

How the texture wraps

dirtyStyleId number protected

Used by TextureSystem to only update texture style when needed.

touched number protected

Used by automatic texture Garbage Collection, stores last GC tick when it was bound

uid number protected

Global unique identifier for this BaseTexture

Methods

PIXI.BaseTexture.addToCache (baseTexture, id) void 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, strict) 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 Attributes Default Description
source string | HTMLImageElement | HTMLCanvasElement | SVGElement | HTMLVideoElement

The source to create base texture from.

options object <optional>

See PIXI.BaseTexture's constructor for options.

options.pixiIdPrefix string <optional>
pixiid

If a source has no id, this is the prefix of the generated id

strict boolean <optional>

Enforce strict-mode, see PIXI.settings.STRICT_TEXTURE_CACHE.

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 Attributes Description
buffer Float32Array | Uint8Array

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 (canvas, scaleMode) PIXI.BaseTexture Deprecated`` : since 5.0.0 static

Name Type Description
canvas HTMLCanvasElement
scaleMode number
See:
Returns:
Type Description
PIXI.BaseTexture

PIXI.BaseTexture.fromSVG (canvas, crossorigin, scaleMode, scale) PIXI.BaseTexture Deprecated`` : since 5.0.0 static

Name Type Description
canvas HTMLCanvasElement
crossorigin string | boolean
scaleMode number
scale number
See:
Returns:
Type Description
PIXI.BaseTexture

PIXI.BaseTexture.removeFromCache (baseTexture) PIXI.BaseTexture | unknown 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 | unknown The BaseTexture that was removed.

castToBaseTexture () PIXI.BaseTexture

Utility function for BaseTexture|Texture cast

Returns:
Type Description
PIXI.BaseTexture

destroy () void

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

dispose () void

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#dispose

getDrawableSource () PIXI.ICanvasImageSource

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

Returns:
Type Description
PIXI.ICanvasImageSource Source to render with CanvasRenderer

loadSource (image) void Deprecated`` : since 5.0.0

Name Type Description
image string | HTMLImageElement

setRealSize (realWidth, realHeight, resolution) PIXI.BaseTexture

Sets real size of baseTexture, preserves current resolution.

Name Type Attributes Description
realWidth number

Full rendered width

realHeight number

Full rendered height

resolution number <optional>

Optionally set resolution

Returns:
Type Description
PIXI.BaseTexture this

setResolution (resolution) PIXI.BaseTexture

Changes resolution

Name Type Description
resolution number

res

Returns:
Type Description
PIXI.BaseTexture this

setResource (resource) PIXI.BaseTexture

Sets the resource if it wasn't set. Throws error if resource already present

Name Type Description
resource PIXI.Resource

that is managing this BaseTexture

Returns:
Type Description
PIXI.BaseTexture this

setSize (width, height, resolution) PIXI.BaseTexture

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

Name Type Attributes Description
width number

Visual width

height number

Visual height

resolution number <optional>

Optionally set resolution

Returns:
Type Description
PIXI.BaseTexture this

setStyle (scaleMode, mipmap) PIXI.BaseTexture

Changes style options of BaseTexture

Name Type Attributes Description
scaleMode PIXI.SCALE_MODES <optional>

Pixi scalemode

mipmap PIXI.MIPMAP_MODES <optional>

enable mipmaps

Returns:
Type Description
PIXI.BaseTexture this

update () void overrides

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

Events

Fired when BaseTexture is destroyed.

Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being destroyed.

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

Name Type Description
baseTexture PIXI.BaseTexture

Resource errored.

event ErrorEvent

Load error event.

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

Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

Fired when BaseTexture is updated.

Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

Fired when BaseTexture is updated.

Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being updated.