Three.js Sprite Sheet Animator (Flipbook Billboards)
Flipbook sprite animation in Three.js from a packed 8×3 sprite sheet (coin spin, explosion, walk cycle) on hundreds of instanced camera-facing billboards, with per-instance phase, frame blending and a live atlas preview.
Key topics: three.js sprite sheet, flipbook animation, texture atlas, billboard, instancedmesh, 2d animation
Game Over
What this code does
- Sprite Sheet: animations are packed into a grid atlas, one row per animation and one column per frame.
- Flipbook UVs: the vertex shader picks column floor(time × fps + phase) and the row, then scales uv into that cell.
- Billboarding: quads are expanded in view space, so they always face the camera without per-frame CPU work.
- Instancing: hundreds of sprites with random phase, row and size render in one draw call through instanced attributes.
- Frame Blending: optionally cross-fade between the current and next frame for smoother low-fps playback.
- Atlas Preview: the sheet is shown in-scene with the current frame cell outlined per row.
- Controls: fps, animation row, frame blending, sprite count, atlas and loading your own 8×3 sheet.
Related Demos
Continue Learning
JavaScript Implementation
// Flipbook UVs: pick column = floor(time × fps) and the animation's row in the atlas
const flipbook = `
float f = mod(floor(uTime * uFps + aPhase * 8.0), 8.0); // per-instance phase offset
vec2 cell = vec2(1.0 / 8.0, 1.0 / 3.0);
vUv = vec2(f * cell.x, 1.0 - (aRow + 1.0) * cell.y) + uv * cell;
vec4 mv = modelViewMatrix * instanceMatrix * vec4(0.0, 0.0, 0.0, 1.0);
mv.xy += position.xy * aScale; // billboard toward the camera
gl_Position = projectionMatrix * mv;`
const geometry = new THREE.PlaneGeometry(1, 1)
geometry.setAttribute('aPhase', new THREE.InstancedBufferAttribute(phases, 1))
const sprites = new THREE.InstancedMesh(geometry, flipbookMaterial, 300)