pixi.js - Documentation

What is PixiJS?

PixiJS is a fast, lightweight 2D rendering engine for creating interactive web applications and games. It uses WebGL for hardware acceleration whenever possible, falling back to Canvas for browsers that don’t support WebGL. This provides a smooth and performant experience across a wide range of devices and browsers. PixiJS handles the complexities of rendering, allowing developers to focus on creating engaging visual content and interactive experiences. It offers a clean and intuitive API that simplifies common tasks like sprite animation, particle effects, and text rendering. The library is built on top of modern JavaScript and is compatible with various build tools and frameworks.

Why use PixiJS?

PixiJS offers several compelling advantages for 2D game and application development:

Setting up your development environment

To start developing with PixiJS, you’ll need:

  1. A code editor: Choose a code editor you’re comfortable with (VS Code, Sublime Text, Atom, etc.).

  2. Node.js and npm (or yarn): PixiJS is typically installed via npm or yarn, which require Node.js to be installed on your system. Download and install Node.js from https://nodejs.org/.

  3. PixiJS: Install PixiJS using npm or yarn:

    npm install pixi.js

    or

    yarn add pixi.js
  4. A web server (optional but recommended): While you can run PixiJS applications directly from file paths in some browsers, using a local web server (like http-server or Python’s SimpleHTTPServer) is generally recommended for proper functionality and debugging. You can install http-server via npm:

    npm install -g http-server

    Then navigate to your project directory in the terminal and run:

    http-server

Basic project structure

A basic PixiJS project typically consists of the following files:

Example index.html:

<!DOCTYPE html>
<html>
<head>
    <title>My PixiJS App</title>
</head>
<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/7.3.0/pixi.min.js"></script>
    <script src="app.js"></script>
</body>
</html>

Remember to adjust file paths according to your project structure. Using a module bundler (like Webpack or Parcel) is recommended for larger projects to manage dependencies and optimize your code.

Core Concepts

The Renderer

The PixiJS renderer is responsible for drawing the scene to the canvas. It handles all the low-level rendering tasks, including WebGL rendering (if supported) and Canvas fallback. You don’t typically interact directly with the renderer in most cases; the Application object manages it for you. However, understanding its role is crucial for performance optimization. The renderer handles:

The Renderer class provides methods for advanced customization, such as resizing the render area and changing render options.

Display Objects

Display objects are the fundamental building blocks of your PixiJS applications. They represent visual elements on the screen, such as images, text, shapes, and more. Each display object has properties for position, scale, rotation, visibility, and more. Key display object classes include Sprite, Graphics, Text, and Container. All display objects inherit from the base DisplayObject class.

Containers

Containers are special display objects that can hold other display objects. This allows you to organize and manage your scene’s elements in a hierarchical structure. Containers inherit all properties of DisplayObject and add the ability to add and remove child display objects. This hierarchical structure is essential for managing complex scenes efficiently. Using containers improves organization, simplifies transformations (applying transformations to a container affects all its children), and optimizes rendering by grouping related objects.

Textures

Textures represent the visual data used to render display objects. They are typically loaded from images but can also be generated dynamically. A texture is essentially a wrapper around an image that provides methods to access pixel data, apply filters, and handle other image-related operations. Efficient texture management is crucial for performance in PixiJS applications. Considerations include texture atlases (combining multiple images into one for optimized rendering) and proper texture sizes to avoid unnecessary memory consumption.

Sprites

Sprites are the most common type of display object in PixiJS. They represent images and are created using a Texture. Sprites inherit from DisplayObject and provide methods for controlling position, scale, rotation, alpha, and other visual properties. They are highly optimized for rendering and are the foundation for many game elements and interactive visuals. Creating sprites involves loading an image as a texture and then using that texture to create a Sprite instance.

Stage and Scene Graph

The stage is the root container of your application. All other display objects are added to the stage (directly or indirectly through nested containers). The stage represents the entire scene being rendered. The arrangement of display objects within the stage defines the scene graph, a hierarchical tree structure reflecting the parent-child relationships between display objects. This tree structure determines the rendering order and how transformations are applied.

Coordinate Systems

PixiJS uses a 2D Cartesian coordinate system. The origin (0, 0) is typically located at the top-left corner of the stage. Positive x-values extend to the right, and positive y-values extend downwards. Understanding coordinate systems is crucial for positioning display objects accurately within your scene. Container transformations affect the coordinate system of their children.

Transformation Matrix

Each display object has a transformation matrix that defines its position, scale, rotation, and skew. This matrix is used by the renderer to calculate the final position and appearance of the object on the screen. Manipulating the transformation matrix directly provides fine-grained control over an object’s visual properties but is generally less intuitive than using the simpler x, y, scale, and rotation properties.

Interaction

PixiJS provides tools for handling user input, including mouse and touch events. Events are dispatched to the display objects when the user interacts with them. You can attach event listeners to display objects to respond to mouse clicks, drags, hovers, and touch events. Interaction is critical for creating interactive games and applications.

Events

PixiJS uses a standard event system, allowing you to listen for and respond to various events. These events are triggered by user interactions or internal application events. Common events include pointerdown, pointerup, pointermove, mousedown, mouseup, mousemove, and more. Event listeners are attached to display objects using the addListener method. Event handling is fundamental for creating responsive and interactive applications.

Ticker

The Ticker is a class that manages the update loop of your application. It dispatches a tick event at a regular interval, typically tied to the browser’s animation frame. You can use the Ticker to update the state of your display objects and handle animation. It provides methods for starting, stopping, and managing the update rate of the loop. Efficiently using the Ticker is crucial for creating smooth animations and avoiding performance issues. In most cases, you’ll use the Application’s built-in ticker rather than creating a Ticker instance directly.

Working with Display Objects

Creating Display Objects

Creating display objects involves instantiating the appropriate class and configuring its properties. For example, to create a sprite from an image, you’ll first load the image as a texture and then use that texture to create a Sprite instance.

// Load the texture (assuming 'image.png' is in your assets folder)
const texture = PIXI.Texture.from('image.png');

// Create a sprite using the texture
const sprite = new PIXI.Sprite(texture);

// Add the sprite to the stage
app.stage.addChild(sprite);

Other display objects, like Graphics (for drawing shapes) and Text (for rendering text), are created similarly, but with different parameters and methods. Refer to the PixiJS API documentation for details on specific display object classes and their constructors.

Adding and removing children

Display objects are added to containers (including the stage) using the addChild method. You can add multiple children to a container, creating a hierarchical structure. Children are removed using the removeChild method. Methods like addChildAt, removeChildAt, swapChildren, and sortChildren offer finer control over the order and arrangement of children within a container.

// Add a child to a container
container.addChild(sprite);

// Remove a child from a container
container.removeChild(sprite);

Positioning and scaling

The position of a display object is determined by its x and y properties. These properties represent the object’s position relative to its parent container. Scaling is controlled by the scale property, which is a Point object with x and y components for horizontal and vertical scaling.

// Set the position of a sprite
sprite.x = 100;
sprite.y = 50;

// Set the scale of a sprite
sprite.scale.x = 2;
sprite.scale.y = 1.5;

Rotation and pivots

Rotation is controlled by the rotation property, which represents the rotation angle in radians. The pivot point determines the center of rotation. By default, the pivot is at (0, 0) (top-left corner). Modifying the pivot property (a Point object) changes the center of rotation.

// Rotate the sprite by 45 degrees (π/4 radians)
sprite.rotation = Math.PI / 4;

// Set the pivot point to the center of the sprite
sprite.pivot.x = sprite.width / 2;
sprite.pivot.y = sprite.height / 2;

Visibility and alpha

The visible property controls whether a display object is rendered. Setting visible to false hides the object. The alpha property controls the object’s transparency, ranging from 0 (fully transparent) to 1 (fully opaque).

// Hide the sprite
sprite.visible = false;

// Set the sprite's alpha to 50%
sprite.alpha = 0.5;

Masks and filters

Masks allow you to clip a display object to a specific shape, revealing only the portion of the object that overlaps with the mask. Filters modify the appearance of a display object, applying effects like blur, color adjustments, and more. Both masks and filters are applied using the mask and filters properties respectively.

Caching

Caching renders a display object to a texture, improving performance by reducing the number of draw calls needed to render the object and its children. Caching is particularly beneficial for complex display objects that rarely change. Use the cacheAsBitmap property to enable or disable caching. Note that overusing caching can lead to memory issues.

Managing memory

Efficient memory management is essential for creating performant PixiJS applications. Techniques for managing memory include:

Graphics and Shapes

Creating Graphics Objects

Graphics objects in PixiJS allow you to draw custom shapes and lines directly onto the canvas. You create a Graphics object using the PIXI.Graphics constructor. Unlike sprites which use textures, Graphics objects build their visual representation using methods that define lines, curves, and fills. All drawing commands are recorded internally and rendered efficiently by PixiJS.

Drawing lines, rectangles, circles, and other shapes

The Graphics object provides methods to draw various shapes:

Example: Drawing a rectangle and a circle:

const graphics = new PIXI.Graphics();
graphics.beginFill(0xFF3300); // Red fill
graphics.drawRect(50, 50, 100, 50);
graphics.beginFill(0x00FF00); // Green fill
graphics.drawCircle(200, 100, 50);
graphics.endFill();
app.stage.addChild(graphics);

Using Paths

For more complex shapes, use paths. Start a path with moveTo(x, y), then add points using lineTo(x, y), quadraticCurveTo(cpx, cpy, x, y), or bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) to create curves. Close a path with closePath().

const graphics = new PIXI.Graphics();
graphics.lineStyle(4, 0xFF0000, 1);
graphics.beginFill(0xFFFF00, 0.5);
graphics.moveTo(50, 50);
graphics.lineTo(250, 50);
graphics.lineTo(150, 150);
graphics.closePath();
graphics.endFill();
app.stage.addChild(graphics);

Filling and stroking graphics

beginFill(color, alpha) starts filling shapes with the specified color and alpha. endFill() stops filling. lineStyle(lineWidth, color, alpha) sets the line style before drawing shapes. You can combine filling and stroking to create varied visual effects.

Working with colors and gradients

Colors are specified using hexadecimal values (e.g., 0xFF0000 for red). PixiJS also supports gradients. While there’s no direct gradient method on PIXI.Graphics, you can achieve gradient effects by creating multiple filled shapes with slightly varying colors and positioning them appropriately.

Managing complex graphics

For complex graphics with many shapes or paths, consider:

Remember to call app.renderer.render(app.stage) or equivalent to force an update if you modify a Graphics object after it has already been added to the stage.

Textures and Sprites

Loading textures from images

Textures in PixiJS represent the visual data used to render sprites. The most common way to create a texture is by loading an image. This can be done using PIXI.Texture.from() or PIXI.Loader.add().

Using PIXI.Texture.from(): This method loads an image directly, suitable for simple cases:

const texture = PIXI.Texture.from('image.png');
const sprite = new PIXI.Sprite(texture);
app.stage.addChild(sprite);

Using PIXI.Loader.add(): This is better for managing multiple assets and handling loading progress:

const loader = new PIXI.Loader();
loader.add('image.png');
loader.load((loader, resources) => {
  const texture = resources['image.png'].texture;
  const sprite = new PIXI.Sprite(texture);
  app.stage.addChild(sprite);
});

Remember to place your images in a directory accessible to your HTML file.

Creating sprites from textures

Once you have a texture, you create a sprite using the PIXI.Sprite constructor, passing the texture as an argument. The sprite then becomes a display object you can manipulate (position, scale, rotation, etc.) within the scene graph.

Texture atlases

Texture atlases combine multiple images into a single texture, optimizing rendering performance by reducing the number of texture uploads to the GPU. To use a texture atlas, you’ll need a texture atlas file (usually a JSON file specifying the location of each sub-image within the atlas image) and the atlas image itself. PixiJS doesn’t directly load atlases; you need to use a separate tool (like Texture Packer) to generate the atlas and then load the image and JSON data separately. Then, use PIXI.Texture.from to load individual frames from the atlas, referencing their coordinates as specified in the atlas JSON data.

Sprite animations

Sprite animations involve displaying a sequence of images (frames) rapidly to create the illusion of movement. You can achieve this by creating multiple sprites, each with a different frame from an animation sprite sheet, and then switching between them rapidly using the Ticker. Alternatively, you can use a library built on top of PixiJS to simplify animation sequences. A common approach is to load a spritesheet (an image containing all frames of the animation) and then use PIXI.Texture.from with frame coordinates to access each individual frame from the spritesheet.

Working with texture regions

A texture region defines a rectangular area within a texture. You can create sub-textures from a larger texture using PIXI.Rectangle and PIXI.Texture.from. This is particularly useful for working with sprite sheets where each animation frame is a region within the larger sheet image. This allows you to specify which specific portion of the texture should be used for rendering. This avoids creating a separate PIXI.Texture for each frame from a spritesheet. For example:

const texture = PIXI.Texture.from('spritesheet.png');
const frame = new PIXI.Rectangle(0, 0, 32, 32); // First frame's coordinates and dimensions
const frameTexture = new PIXI.Texture(texture.baseTexture, frame);
const sprite = new PIXI.Sprite(frameTexture);
app.stage.addChild(sprite);

This method is efficient for animation, allowing you to re-use the same base texture for many different sprites and animation frames. Using the frame argument within PIXI.Texture constructor helps control the area within the spritesheet that is displayed. Remember to adjust frame for every different frame in your animation.

Text

Adding Text Objects

To add text to your PixiJS application, use the PIXI.Text class. The constructor takes the text string and style options as arguments.

const style = new PIXI.TextStyle({
    fontFamily: 'Arial',
    fontSize: 36,
    fill: 'white',
    stroke: '#ff3300',
    strokeThickness: 4,
    dropShadow: true,
    dropShadowColor: '#000000',
    dropShadowBlur: 4,
    dropShadowAngle: Math.PI / 6,
    dropShadowDistance: 6,
    wordWrap: true,
    wordWrapWidth: 400
});

const text = new PIXI.Text('Hello PixiJS!', style);
app.stage.addChild(text);

This creates a text object with specified styling. Place the text object within your scene graph like any other display object. The text content can be updated later using the text property.

Styling Text

The PIXI.TextStyle object allows for extensive styling customization. Key properties include:

Font Loading

By default, PixiJS uses system fonts. To use custom fonts, you’ll need to load them beforehand, typically using a <link> tag in your HTML’s <head>:

<link href="path/to/your/font.woff2" rel="preload" as="font" type="font/woff2" crossorigin>
<link href="path/to/your/font.woff" rel="preload" as="font" type="font/woff" crossorigin>

Remember to include the appropriate file types (.woff, .woff2, .ttf, etc.) for browser compatibility. Ensure the font paths in your TextStyle match the loaded fonts. Using @font-face CSS rules is another approach to loading custom fonts.

Text Alignment

Text alignment is controlled by the align property in the TextStyle. Valid values are 'left', 'center', and 'right'. This aligns the text within the text object’s bounding box.

Text Wrapping

Word wrapping is enabled using the wordWrap property set to true in PIXI.TextStyle. The wordWrapWidth property specifies the maximum width before wrapping occurs. This allows you to control how long text lines become before automatically breaking onto a new line. If wordWrap is true, but wordWrapWidth is not provided, the text will not wrap.

Advanced Topics

Shaders

Shaders provide fine-grained control over how objects are rendered in WebGL. PixiJS allows you to create and use custom shaders to achieve advanced visual effects beyond what’s possible with built-in features. Creating a custom shader involves writing GLSL code (a shading language) and then using PixiJS’s shader system to apply it to display objects. This requires understanding of GLSL and how shaders interact with the rendering pipeline.

Filters

Filters modify the appearance of display objects by processing their pixels. PixiJS provides built-in filters (like blur, color matrix, displacement), but you can also create custom filters using the PIXI.Filter class. Custom filters require writing a fragment shader that manipulates pixel data. Applying a filter involves adding it to the filters array of a display object.

Masks

Masks clip display objects to a specific shape, making only the portion of the object overlapping the mask visible. You can use any display object as a mask, including sprites and graphics objects. Applying a mask involves setting the mask property of a display object to the masking object. This effectively “cuts out” a portion of the masked object, revealing only the area visible through the mask’s shape.

Particles

Particles are small graphical elements used to create realistic or stylized visual effects like explosions, smoke, fire, or rain. PixiJS doesn’t have a built-in particle system, but several excellent third-party particle libraries are available that integrate seamlessly with PixiJS. These libraries handle the complexities of particle generation, movement, and rendering, making it easy to add sophisticated particle effects to your applications. Consider these libraries if you need particle functionality.

Custom Renderers

For highly specialized rendering needs or significant performance optimizations, you can create custom renderers. This involves extending the PIXI.Renderer class and overriding its rendering methods to implement your own rendering logic. This is a very advanced topic, requiring a deep understanding of WebGL and PixiJS’s internal workings. This approach is usually only necessary for highly optimized or specialized rendering solutions.

Performance optimization

Optimizing PixiJS applications for performance is crucial for creating smooth and responsive experiences. Key strategies include:

Debugging and troubleshooting

Debugging PixiJS applications often involves using browser developer tools (like those in Chrome or Firefox) to inspect the scene graph, check for errors in the console, and use debugging tools to step through your code. Common issues include incorrect coordinate systems, inefficient rendering practices, memory leaks, and incorrect use of textures. Understanding how PixiJS interacts with WebGL can assist in diagnosing and resolving advanced issues. Checking the PixiJS forums and community resources can often help find solutions for common problems.

Working with External Libraries and Plugins

Integrating PixiJS with other JavaScript libraries

PixiJS is designed to integrate well with other JavaScript libraries. The approach to integration depends on the library and how it interacts with the DOM or canvas. Common integration points include:

In most cases, integration involves properly managing the lifecycle of the different libraries, ensuring correct initialization and ensuring the rendering contexts (if applicable) don’t conflict.

Using PixiJS plugins

PixiJS plugins extend its functionality by adding features or improving existing ones. Plugins can simplify tasks, add new capabilities, or offer optimized solutions for specific problems. Many plugins are available, and some popular examples include plugins for particle systems, advanced text rendering, physics integrations, and UI components.

To use a plugin, follow the plugin’s specific installation and usage instructions. This usually involves installing the plugin (often via npm or yarn), importing it into your project, and then integrating it into your PixiJS application. Ensure the plugin’s version is compatible with your version of PixiJS, following the plugin’s documentation for compatibility details. Many plugins will demonstrate their usage within their README files, including specific examples and integration methods. Pay close attention to the plugin’s setup instructions; some plugins might require specific initialization or configuration steps within your PixiJS code.

Game Development with PixiJS

Creating simple games

PixiJS is well-suited for creating 2D games. A simple game might involve sprites representing game objects, a game loop for updating game state, and input handling for player interaction. Start with a basic structure: load assets (images, sounds), create sprites, add them to the stage, and implement a game loop. Initially, focus on core mechanics before adding more advanced features like physics and complex animations.

Game loops

The game loop is the heart of your game, continuously updating game state and rendering the scene. PixiJS’s Ticker is essential for this; use the update method of the Ticker to handle game logic updates on each frame.

app.ticker.add((delta) => {
    // Update game objects based on delta (time since last frame)
    player.update(delta);
    enemies.forEach(enemy => enemy.update(delta));
    // Check for collisions
    checkCollisions();
    // Render the scene (PixiJS handles this automatically)
});

The delta value helps ensure consistent game speed regardless of frame rate variations.

Input handling

Handle player input using PixiJS’s event system. Attach event listeners (e.g., pointerdown, pointermove, keydown) to display objects or the stage to detect clicks, drags, and keyboard presses. Use these events to control game objects or trigger actions.

player.interactive = true;
player.on('pointerdown', () => {
    player.jump();
});

Collision detection

Collision detection determines when game objects overlap. Simple collision detection can involve comparing bounding boxes of sprites. For more advanced scenarios, use libraries like SAT (Separating Axis Theorem) or other dedicated collision detection libraries that integrate with PixiJS. Consider using bounding circles or more complex polygon collision detection depending on the shapes of your game objects and performance needs.

Game physics

Realistic game physics adds depth and realism. Integrate a physics engine like Matter.js or Planck.js alongside PixiJS. These engines handle physics calculations (gravity, collisions, forces), and you synchronize the results with your PixiJS sprites to visually represent the physics simulation. This simplifies complex physics calculations and allows you to focus on game design rather than low-level physics implementation. Properly integrating the physics engine with PixiJS involves updating the position and other visual aspects of your PixiJS sprites to match the results of the physics simulation at each frame of the game loop.

Examples and Tutorials

This section provides a brief overview of example types. Refer to the official PixiJS website and community resources for complete, runnable code examples and detailed tutorials.

Basic Example

A basic example demonstrates creating a simple scene with a few sprites:

  1. Setup: Create an HTML file including the PixiJS library.
  2. Application: Create a PIXI.Application instance.
  3. Sprites: Load images (textures) and create sprites.
  4. Positioning: Add sprites to the stage and position them.
  5. Rendering: PixiJS automatically renders the scene; no additional rendering code is typically needed.

A skeletal structure would look like this (replace placeholders with actual paths):

const app = new PIXI.Application({ width: 800, height: 600 });
document.body.appendChild(app.view);

const sprite1 = PIXI.Sprite.from("image1.png");
sprite1.x = 100;
sprite1.y = 100;
app.stage.addChild(sprite1);

// Add more sprites similarly

Sprite Animation

Animating a sprite involves loading a sprite sheet (an image containing multiple frames of animation) and then displaying the frames sequentially using the Ticker. This might involve creating multiple textures from the sprite sheet or using a texture atlas. A simple animation might involve changing the texture property of the sprite within the game loop at a set interval. More advanced animation techniques might use external animation libraries or custom solutions.

Particle System

Creating a particle system often involves using a third-party library built for PixiJS (as PixiJS itself doesn’t have a built-in particle system). These libraries simplify the complexities of particle generation, movement, and rendering. The process would involve choosing a suitable particle library, installing it, and then incorporating it into your PixiJS application. You would then configure the particle system’s parameters (like emitter position, particle speed, lifetime, and appearance) to create the desired effect, integrating it with the PixiJS scene within your game loop.

Complex Game Example

A complex game example would demonstrate many aspects of PixiJS: a game loop, input handling, collision detection, physics (potentially using a physics engine), sophisticated sprite animation, sound effects, potentially advanced shaders or filters, and a well-structured codebase. This could be a simple arcade game, a puzzle game, or a small platformer, showcasing the capabilities of PixiJS for creating engaging and feature-rich 2D games. Such examples would be significantly more involved than the simpler examples, showcasing the integration of multiple techniques and libraries. These are usually best explored through tutorials and example projects available online. Many are available on the official PixiJS website, GitHub repositories, and code-sharing sites.

Remember that complete, runnable code for these examples would be too extensive to include in a developer manual section. It’s best to reference the many online tutorials and example projects available within the PixiJS community.

API Reference

This section provides a high-level overview. For complete and up-to-date API documentation, always refer to the official PixiJS website. The API is subject to change between versions.

PIXI Object

The PIXI object is the namespace for all PixiJS classes and functions. It’s the entry point for using the library. Most classes and functions you use will be accessed through this namespace (e.g., PIXI.Application, PIXI.Sprite, PIXI.Texture). It’s the root of all the classes and functionality provided by the PixiJS library.

DisplayObject

PIXI.DisplayObject is the base class for all display objects in PixiJS. It provides core properties and methods common to all visual elements in the scene graph, such as position (x, y), scale (scale.x, scale.y), rotation (rotation), visibility (visible), alpha (alpha), and transformations. It also defines methods for adding event listeners and managing the object’s parenting within the display list. This class is the foundation upon which all other visual elements in PixiJS are built. While you typically don’t directly use DisplayObject instances, understanding its properties and methods is crucial for working with all display objects.

Container

PIXI.Container is a special type of DisplayObject that can contain other display objects. It allows you to organize your scene into a hierarchical structure, simplifying management and enabling efficient rendering. Key methods include addChild(), removeChild(), and methods for managing the order of children. Containers are essential for structuring complex scenes and efficiently managing groups of display objects. Transformations applied to a container affect all its children.

Sprite

PIXI.Sprite represents an image in your scene. It’s created from a PIXI.Texture and inherits from DisplayObject. It provides properties for controlling the sprite’s appearance and behavior, including its texture, position, scale, rotation, alpha, and more. Sprites are fundamental to creating visual elements in most PixiJS applications.

Graphics

PIXI.Graphics allows you to draw shapes and lines directly on the canvas. It’s not texture-based; instead, it uses methods to define shapes (rectangles, circles, polygons, etc.) and their fill and stroke properties. It’s useful for creating custom shapes and visuals not easily represented by images.

Text

PIXI.Text renders text on the screen. You provide the text string and a PIXI.TextStyle object to customize its appearance (font, size, color, alignment, etc.). It inherits from DisplayObject.

Texture

PIXI.Texture represents the visual data used by sprites and other display objects. Textures are typically created from images but can be generated dynamically as well. They manage the image data and provide access to methods for manipulating textures. Efficient texture management is crucial for performance. Understanding how textures work and optimizing their usage is important for application performance, especially in applications with many images.

Renderer

PIXI.Renderer is responsible for drawing the scene to the canvas. It handles WebGL rendering (when available) and Canvas fallback. You usually don’t interact with the renderer directly; the PIXI.Application manages it. However, understanding its role is important for optimizing rendering performance. It handles low-level rendering details, including batching, shader management, and context management. For very advanced use cases, you might extend or customize the renderer, but this is typically not required for most applications.

Note: This is a simplified overview. Each class has numerous properties and methods; consult the official PixiJS API documentation for detailed information.