---
title: "Loop a sprite sheet animation in three.js"
description: "Loop a fire or smoke sprite sheet in three.js: take elapsed time from a Clock, multiply by the frame rate, wrap with the frame count and set the offset."
canonical: https://appliedmanifold.com/guides/threejs-loop-sprite-animation/
site: "Applied Manifold: The spatial compute cloud for 3D reality"
---

1.  [Home](https://appliedmanifold.com/)
2.  [Guides](https://appliedmanifold.com/guides/)
3.  Loop a sprite animation

GUIDE // THREE.JS

# How to loop a fire or smoke sprite sheet animation in three.js

Read the elapsed time from a THREE.Clock inside your animation loop, multiply it by the sheet's frame rate, round down and wrap it with the frame count, then set the texture offset to that frame's cell on every tick. A sheet whose last frame flows into its first then keeps looping without a visible jump.

[Get Free API Key](https://console.appliedmanifold.com/sign-in?next=/api-keys) [See the examples →](https://appliedmanifold.com/docs/pyrofx/examples/)

-   Godot 4 Available
-   Unity Manual setup
-   Unreal Engine Manual setup
-   Roblox Studio Manual setup
-   **three.js** Available

A draft compile is from $0.05, and new accounts start with $5 of usage.

**FIREFINAL**

![First frame of the fire bake](/bakes/fire/poster.webp)

Fire, 4.1 x 7.0 m, compiled with Spatial Compiler. [Spec →](https://appliedmanifold.com/docs/pyrofx/examples/#ex-fire)

01 // HOW TO

## Loop the 2 s fire

1.  Load the sheet and set `texture.repeat` to 1/8 by 1/8, as in [the loading guide](https://appliedmanifold.com/guides/threejs-load-sprite-sheet/).
2.  Take the frame rate from `layout.json`. The fire has 64 frames over 2 s, so 32 frames per second.
3.  Inside `renderer.setAnimationLoop`, compute the frame from elapsed time, wrap it with `% 64` and set the offset.
4.  For the 4 s smoke plume, change the rate to 16.

loopFire.js

```
import * as THREE from 'three';

const FPS = 32;    // 64 frames over the 2 s fire loop
const FRAMES = 64;
const clock = new THREE.Clock();

renderer.setAnimationLoop(() => {
  const frame = Math.floor(clock.getElapsedTime() * FPS) % FRAMES;
  texture.offset.set((frame % 8) / 8, 1 - (Math.floor(frame / 8) + 1) / 8);
  renderer.render(scene, camera);
});
```

02 // REAL OUTPUT

## A slower loop

The smoke plume runs twice as long per loop as the fire, so it needs half the rate.

**SMOKE\_PLUMEFINAL**

![First frame of the smoke\_plume bake](/bakes/smoke_plume/poster.webp)

Smoke plume, 7.0 x 10.8 m, compiled with Spatial Compiler. [Spec →](https://appliedmanifold.com/docs/pyrofx/examples/#ex-smoke_plume)

03 // WHY TIME

## Drive the frame from elapsed time

Adding one frame per tick ties the speed to the screen, so the fire burns twice as fast on a 120 Hz display as on a 60 Hz one. Elapsed time plays the clip at its real speed everywhere, and when a hidden browser tab resumes, the loop picks up at the right frame.

The wrap with `%` only looks right on a sheet made to loop. The looping example compiles from Spatial Compiler blend their last 12 frames into the first, so frame 63 leads into frame 0.

Godot 4 gets a ready scene that relights the smoke. three.js uses the documented snippet. A native six-way material is not built yet.

04 // RELATED

## Related pages

-   [Loop a fire sheet Godot 4Find why a fire loop pops in Godot 4 and fix it in the sheet, the AnimatedSprite3D or the GPUParticles3D emitter settings.](https://appliedmanifold.com/guides/godot-loop-fire-sprite-sheet/)
-   [Loop a flipbook in Niagara Unreal EngineLoop a fire or smoke flipbook without end in Niagara by looping the emitter at the clip length and bursting one particle per loop.](https://appliedmanifold.com/guides/unreal-loop-flipbook/)
-   [Play an explosion once three.jsPlay an explosion sprite sheet once in three.js, then remove the sprite and free its material and texture.](https://appliedmanifold.com/guides/threejs-play-once/)
-   [three.js steady fire three.jsA steady fire about 1.5 m across that loops every 2 seconds, played in three.js with a documented snippet.](https://appliedmanifold.com/effects/threejs-steady-fire/)
-   [three.js VFX three.jsFire, smoke, explosion and dust effects in three.js: sprite sheets you play with a documented snippet, next to Godot 4's ready scene.](https://appliedmanifold.com/effects/threejs-vfx/)
-   [Loops without a seamA loop with no visible seam blends its last frames into its first, so a fire or smoke effect keeps looping without a pop.](https://appliedmanifold.com/learn/seamless-loop/)
-   [OutputsWith the default export, each view writes four sheets, `<view>_pos.png`, `_neg.png`, `_colour.png` and `_aux.png`, plus `layout.json`, two still previews, the animated `preview_anim.png` and `bake_report.json`. Sheets are 8 x 8 tiles of 256 px by default.](https://appliedmanifold.com/docs/pyrofx/outputs/)

[All pages in Guides →](https://appliedmanifold.com/guides/)

[← Sprite sheet UV math](https://appliedmanifold.com/guides/threejs-sprite-sheet-uv/)[Play an explosion once →](https://appliedmanifold.com/guides/threejs-play-once/)

05 // FAQ

## three.js looping sprite questions

[All questions →](https://appliedmanifold.com/faq/)

**README.THREEJS\_LOOP\_SPRITE\_ANIMATION**

### How do I make a fire effect in three.js?

Play a fire sprite sheet on a THREE.Sprite, set texture repeat to one eighth, step the offset through 64 frames and use additive blending.

### Does three.js have a sprite sheet animation helper?

No built in helper exists. You set texture repeat and offset per frame in a few lines of code or use a small shader.

### How do I loop a smoke plume sprite sheet in three.js?

Advance a frame counter at 64 frames per 4 seconds, wrap it modulo 64 and set texture.offset from the column and row.

### How do I calculate UV coordinates for a sprite sheet with rows and columns in three.js?

Set `texture.repeat` to `1/C` by `1/R`. Compute column `n % C` and row `Math.floor(n / C)`, then offset X by `column / C` and Y from the top.

## Compile your first effect

You pay per compile and see the price before it runs. New accounts start with $5 of usage.

[Get Free API Key](https://console.appliedmanifold.com/sign-in?next=/api-keys) [Outputs →](https://appliedmanifold.com/docs/pyrofx/outputs/)

[All effects, guides and explainers →](https://appliedmanifold.com/effects/)
