---
title: "Play an explosion sprite sheet once in three.js"
description: "Play an explosion flipbook once in three.js: time frames from the spawn moment, stop at the last one, then remove the sprite and dispose of its material."
canonical: https://appliedmanifold.com/guides/threejs-play-once/
site: "Applied Manifold: The spatial compute cloud for 3D reality"
---

1.  [Home](https://appliedmanifold.com/)
2.  [Guides](https://appliedmanifold.com/guides/)
3.  Play an explosion once

GUIDE // THREE.JS

# How to play an explosion flipbook once in three.js and remove it

Record the time when your explosion starts, compute the frame from the time since then, and stop at the last frame instead of wrapping. Once the frame passes the end, remove the sprite from the scene and dispose of its material and its cloned texture, so a scene full of repeated blasts does not leak memory.

[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.

**FIREBALLFINAL**

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

Fireball, 9.4 x 13.4 m, compiled with Spatial Compiler. [Spec →](https://appliedmanifold.com/docs/pyrofx/examples/#ex-fireball)

01 // HOW TO

## Spawn and clean up a fireball

1.  Load the fireball sheet once with `loadAsync` and keep it as the base texture.
2.  For each blast, clone the base texture so this sprite can show its own frame, and set its repeat to 1/8 by 1/8.
3.  Store the start time with the sprite, then each tick find the frame for the time since the start in the frame times from `layout.json`. The fireball's 64 frames span 4 s and bunch up early, so a fixed rate would play the burst too slowly.
4.  When the time passes the clip's end, remove the sprite and dispose of the clone and the material.

explosions.js

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

const FRAMES = 64;
const CLIP = 4; // fireball: its 64 frames span 4 s
const base = await new THREE.TextureLoader().loadAsync('/fx/fireball_rgba.png');
base.colorSpace = THREE.SRGBColorSpace;
const active = [];

export function spawnExplosion(scene, position, size, now) {
  const map = base.clone();
  map.needsUpdate = true;
  map.repeat.set(1 / 8, 1 / 8);
  const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map, transparent: true, depthWrite: false }));
  sprite.position.copy(position);
  sprite.scale.set(size, size, 1);
  scene.add(sprite);
  active.push({ sprite, start: now });
}

// times: the 64 frame start times in seconds, from layout.json
export function updateExplosions(now, times) {
  for (let i = active.length - 1; i >= 0; i--) {
    const { sprite, start } = active[i];
    const t = now - start;
    if (t >= CLIP) {
      sprite.removeFromParent();
      sprite.material.map.dispose();
      sprite.material.dispose();
      active.splice(i, 1);
    } else {
      let frame = 0;
      while (frame + 1 < FRAMES && times[frame + 1] <= t) frame++;
      sprite.material.map.offset.set((frame % 8) / 8, 1 - (Math.floor(frame / 8) + 1) / 8);
    }
  }
}
```

Pass the same clock time, in seconds, as `now` to both functions, for example from `clock.getElapsedTime()`, and pass the frame times you read from the compile's `layout.json` as `times`.

02 // REAL OUTPUT

## A shorter blast

Impact is a flash, thrown earth and a little smoke. Its frames span 3.2 s, so set `CLIP` to 3.2 and use its own frame times.

**IMPACTFINAL**

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

Impact, 3.5 x 2.8 m, compiled with Spatial Compiler. [Spec →](https://appliedmanifold.com/docs/pyrofx/examples/#ex-impact)

03 // HOW IT ENDS

## Why the sprite can vanish at the end

A one-shot compile runs until the effect has faded, so the fireball's frame 63 is almost empty and removing the sprite after it shows no pop. The clone shares the image with the base texture, so each blast costs a material and a texture object, not another copy of the PNG.

If you spawn many blasts a second, keep a small pool of sprites, hide finished ones with `sprite.visible = false` and reuse them instead of disposing.

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

-   [One-shot explosion Godot 4Build a GPUParticles3D explosion in Godot 4 that plays once and frees itself, by hand or from a wired fireball scene.](https://appliedmanifold.com/guides/godot-one-shot-explosion/)
-   [Play an explosion once UnityMake a Unity Particle System play an explosion flipbook a single time and destroy itself, with a prefab and a spawn script.](https://appliedmanifold.com/guides/unity-play-explosion-once/)
-   [Loop a sprite animation three.jsLoop a fire or smoke sprite sheet in three.js from elapsed time, so it plays at the same speed on every screen.](https://appliedmanifold.com/guides/threejs-loop-sprite-animation/)
-   [three.js fireball three.jsA fireball that bursts from the ground and rolls upward in 3.7 seconds, played in three.js with a documented snippet.](https://appliedmanifold.com/effects/threejs-fireball/)
-   [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/)
-   [Loop vs one-shotLooping effects repeat until stopped and one-shot effects play once and fade out, and each needs its own frames and settings.](https://appliedmanifold.com/learn/loop-vs-one-shot/)
-   [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/)

[← Loop a sprite animation](https://appliedmanifold.com/guides/threejs-loop-sprite-animation/)[Random start frame →](https://appliedmanifold.com/guides/threejs-random-start-frame/)

05 // FAQ

## three.js one-shot explosion questions

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

**README.THREEJS\_PLAY\_ONCE**

### Is there a one shot explosion effect for three.js?

Yes. Ask your agent for an explosion that plays once, starting from the fireball or impact example, then play the packed sheet.

### How do I play a smoke column once and remove it in three.js?

Pick each frame from layout.frame\_times\_s, stop after frame 63 at 5 seconds, then call sprite.removeFromParent() and material.dispose().

### How do I play an explosion flipbook once and remove it in three.js?

Advance frames with THREE.Clock, stop at the last frame and call sprite.removeFromParent and material.dispose to clean up.

### How many frames does a fireball effect use?

The fireball compile uses 64 frames over a 4 s clip with more frames on the fast burst and an empty final frame.

## 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/)
