What is pixi.js?
Pixi.js is a fast 2D rendering engine that uses WebGL and HTML5 Canvas to create interactive graphics and animations. It is widely used for creating games, interactive applications, and other visual content on the web.
What are pixi.js's main functionalities?
Creating a Basic Application
This code initializes a new Pixi.js application with a specified width and height, and appends the canvas element to the document body.
const app = new PIXI.Application({ width: 800, height: 600 });
document.body.appendChild(app.view);
Loading and Displaying a Sprite
This code loads an image and creates a sprite from it. The sprite is then positioned at the center of the canvas and added to the stage.
PIXI.Loader.shared.add('bunny', 'path/to/bunny.png').load((loader, resources) => {
const bunny = new PIXI.Sprite(resources.bunny.texture);
bunny.x = app.renderer.width / 2;
bunny.y = app.renderer.height / 2;
bunny.anchor.set(0.5);
app.stage.addChild(bunny);
});
Animating a Sprite
This code adds an animation loop that rotates the sprite continuously. The `delta` parameter ensures smooth animation regardless of the frame rate.
app.ticker.add((delta) => {
bunny.rotation += 0.1 * delta;
});
Creating Graphics
This code creates a new graphics object, draws a filled rectangle, and adds it to the stage.
const graphics = new PIXI.Graphics();
graphics.beginFill(0xDE3249);
graphics.drawRect(50, 50, 100, 100);
graphics.endFill();
app.stage.addChild(graphics);
Other packages similar to pixi.js
three
Three.js is a popular 3D library that provides a wide range of features for creating 3D graphics and animations. While Pixi.js focuses on 2D rendering, Three.js is more suitable for complex 3D scenes and visualizations.
phaser
Phaser is a fast, robust, and versatile game framework that supports both 2D and 3D rendering. It is more game-oriented compared to Pixi.js, offering built-in physics, input handling, and other game development features.
konva
Konva is a 2D canvas library that provides a high-level API for creating complex shapes, animations, and interactions. It is similar to Pixi.js but focuses more on ease of use and simplicity for creating interactive graphics.
Examples | Getting Started | Documentation | Discord
PixiJS ⚡️
Next-Generation, Fastest HTML5 Creation Engine for the Web
- 🚀 WebGL & WebGPU Renderers
- ⚡️ Unmatched Performance & Speed
- 🎨 Easy to use, yet powerful API
- 📦 Asset Loader
- ✋ Full Mouse & Multi-touch Support
- ✍️ Flexible Text Rendering
- 📐 Versatile Primitive and SVG Drawing
- 🖼️ Dynamic Textures
- 🎭 Masking
- 🪄 Powerful Filters
- 🌈 Advanced Blend Modes
PixiJS is the fastest, most lightweight 2D library available for the web, working
across all devices and allowing you to create rich, interactive graphics and cross-platform applications using WebGL and WebGPU.
Setup
It's easy to get started with PixiJS! Just use our PixiJS Create CLI and get set up in just one command:
npm create pixi.js@latest
or to add it to an existing project:
npm install pixi.js
Usage
import { Application, Assets, Sprite } from 'pixi.js';
(async () =>
{
const app = new Application();
await app.init({ background: '#1099bb', resizeTo: window });
document.body.appendChild(app.canvas);
const texture = await Assets.load('https://pixijs.com/assets/bunny.png');
const bunny = new Sprite(texture);
bunny.anchor.set(0.5);
bunny.x = app.screen.width / 2;
bunny.y = app.screen.height / 2;
app.stage.addChild(bunny);
app.ticker.add((time) =>
{
bunny.rotation += 0.1 * time.deltaTime;
});
})();
Contribute
Want to be part of the PixiJS project? Great! All are welcome! We will get there quicker
together :) Whether you find a bug, have a great feature request, or you fancy owning a task
from the road map above, feel free to get in touch.
Make sure to read the Contributing Guide
before submitting changes.
License
This content is released under the MIT License.
Change Log
Releases
Support
We're passionate about making PixiJS the best graphics library possible. Our dedication comes from our love for the project and community. If you'd like to support our efforts, please consider contributing to our open collective.