Fast 2D graphics for browser games with PixiJS (v8). Application setup and resizing, the scene graph (Container, Sprite, Graphics, Text, BitmapText), loading assets and spritesheets with Assets, animated sprites, the ticker and your own fixed-step loop, batching rules for thousands of sprites, ParticleContainer, TilingSprite for parallax, filters and custom shaders, pixel-art settings, input wi...
Download skill (.zip) Files on GitHubPixiJS game development
Pixi is a renderer, not a game engine: you bring the loop, physics, input and states (the game-scaffolding layout works well with Pixi replacing the canvas drawing). Use Phaser (or Bash’s game-kit-2d) if you want a full framework.
Setup (v8)
import { Application, Assets, Sprite, Container, AnimatedSprite, TextureStyle } from "pixi.js"; // pin the version
TextureStyle.defaultOptions.scaleMode = "nearest"; // pixel art only
const app = new Application();
await app.init({ resizeTo: window, background: "#1d1d2b", antialias: false, autoDensity: true, resolution: Math.min(devicePixelRatio, 2) });
document.body.appendChild(app.canvas);
await Assets.load(["assets/img/atlas.json", "assets/img/bg.png"]); // spritesheet JSON (TexturePacker) loads its PNG
const world = new Container(); app.stage.addChild(world);
const hero = new AnimatedSprite(Assets.get("assets/img/atlas.json").animations.run); // tags/animations from the sheet
hero.animationSpeed = 0.2; hero.anchor.set(0.5, 1); hero.play(); world.addChild(hero);
Loop
let acc = 0; const STEP = 1 / 60;
app.ticker.add((t) => {
acc += Math.min(t.deltaMS / 1000, 0.25);
while (acc >= STEP) { update(STEP); acc -= STEP; } // game logic at a fixed step
syncSprites(acc / STEP); // copy positions (interpolated) to Pixi objects
});
Keep game state in plain objects; Pixi objects just mirror it. That keeps logic testable and swappable.
Speed
- Batching: sprites sharing one texture source (atlas) draw together. Interleaving Graphics, Text or different textures breaks batches.
ParticleContainerfor huge counts of simple sprites (particles, bullets).cacheAsTexture()(v8) for static containers (UI panels, tilemap chunks).BitmapTextfor numbers that change every frame (score, damage numbers).Textre-renders a texture on every change.- Cull off-screen objects (
cullable = trueplus a culler, or skip adding them).
Other pieces
- Parallax:
TilingSpritewithtilePosition.x = -camX * factor(parallax-backgrounds). - Filters: built-ins (blur, color matrix, displacement) and custom ones (shader-development).
- Input:
sprite.eventMode = "static"; sprite.on("pointerdown", …)for UI. Use your own input module for gameplay controls. - Cleanup:
sprite.destroy();container.destroy({ children: true });Assets.unload(url)for level assets (game-memory-management).
Check
Pixi uses WebGL (or WebGPU): verify in the viewer’s preview or check_gpu_render, never in the sandbox browser.