Namespace: resources

PIXI.resources

Collection of base resource types supported by PixiJS.

Resources are used by PIXI.BaseTexture to handle different media types such as images, video, SVG graphics, etc. In most use-cases, you should not instantiate the resources directly. The easy thing is to use PIXI.BaseTexture.from.

Example

const baseTexture = PIXI.BaseTexture.from('path/to/image.jpg');

Classes

ArrayResource
BaseImageResource
BufferResource
CanvasResource
CubeResource
DepthResource
ImageBitmapResource
ImageResource
Resource
SVGResource
VideoResource

Members

PIXI.resources.INSTALLED Array.<*> staticreadonly

Collection of installed resource types, class must extend PIXI.resources.Resource.

Example
class CustomResource extends PIXI.resources.Resource {
  // MUST have source, options constructor signature
  // for auto-detected resources to be created.
  constructor(source, options) {
    super();
  }
  upload(renderer, baseTexture, glTexture) {
    // upload with GL
    return true;
  }
  // used to auto-detect resource
  static test(source, extension) {
    return extension === 'xyz'|| source instanceof SomeClass;
  }
}
// Install the new resource type
PIXI.resources.INSTALLED.push(CustomResource);

Methods

PIXI.resources.autoDetectResource (source, options)PIXI.resources.Resource static

Create a resource element from a single source element. This auto-detects which type of resource to create. All resources that are auto-detectable must have a static test method and a constructor with the arguments (source, options?). Currently, the supported resources for auto-detection include:

Name Type Description
source string | *

Resource source, this can be the URL to the resource, a typed-array (for BufferResource), HTMLVideoElement, SVG data-uri or any other resource that can be auto-detected. If not resource is detected, it's assumed to be an ImageResource.

options object optional

Pass-through options to use for Resource

Name Type Default Description
width number optional

Width of BufferResource or SVG rasterization

height number optional

Height of BufferResource or SVG rasterization

autoLoad boolean true optional

Image, SVG and Video flag to start loading

scale number 1 optional

SVG source scale. Overridden by width, height

createBitmap boolean PIXI.settings.CREATE_IMAGE_BITMAP optional

Image option to create Bitmap object

crossorigin boolean true optional

Image and Video option to set crossOrigin

autoPlay boolean true optional

Video option to start playing video immediately

updateFPS number 0 optional

Video option to update how many times a second the texture should be updated from the video. Leave at 0 to update at every render

Returns:
Type Description
PIXI.resources.Resource The created resource.