Skip to main content

Display Animations

This guide explains how to display animations in RPG-JS. There are three common types of animations you can create and display:
  1. Spritesheet Animations - Using image spritesheets with the built-in animation system
  2. Custom Component Animations - Creating your own Canvas Engine components for complex effects
  3. CanvasEngine FX Animations - Using the prebuilt Fx component animation for particle effects
If one server-side gameplay moment should trigger several client visuals at once, such as a flash, sound, hit text, and component animation, use Client Visuals to group those primitives on the client and send only one compact server event.

Spritesheet Animations

See also: Spritesheets Guide for comprehensive information about spritesheets, including dynamic spritesheet resolution.

1. Creating the Animation Spritesheet

First, you need to create an animation spritesheet and add it to your module’s spritesheets configuration.

Using AnimationSpritesheetPreset

The easiest way is to use the built-in AnimationSpritesheetPreset helper:
The AnimationSpritesheetPreset(framesWidth, framesHeight) automatically generates frame coordinates for a grid-based spritesheet. For example, AnimationSpritesheetPreset(4, 4) creates 16 frames arranged in a 4x4 grid.

Manual Spritesheet Configuration

You can also manually configure your spritesheet:

2. Displaying Spritesheet Animations

On a Player

Use the showAnimation method on a player instance:
Examples:

On a Map

Use the showAnimation method on a map instance:
Examples:

Custom Component Animations

For more complex animations with custom logic, you can create Canvas Engine components.
There are two different prop shapes in the client rendering pipeline:
  • scene components loaded with provideLoadMap() receive data and params
  • component animations rendered with showComponentAnimation() receive their props directly (x, y, onFinish, and your custom params)
The examples below are for componentAnimations, not for custom map scene components.

1. Creating a Custom Animation Component

Create a Canvas Engine component file (e.g., ExplosionComponent.ce):
This direct prop shape matches how component animations are rendered in draw-map.ce:
By contrast, custom map scene components are mounted from canvas.ce with a data object:

2. Registering the Component Animation

Add your component to the module configuration:

3. Using the Prebuilt FX Component

RPGJS includes a ready-to-use component animation wrapper for the CanvasEngine Fx preset system. Register it like any other component animation:
Then call it with showComponentAnimation() and pass CanvasEngine Fx props:
Useful built-in Fx names include hitSpark, slashSpark, impactBurst, smokePuff, dustStep, dashDust, magicBurst, healPulse, pickup, levelUp, and explosionSmall. For looped FX, pass displayDuration to tell RPGJS when to remove the temporary component:
You can also pass a custom CanvasEngine preset object from client-side code. When triggering an animation from the server, keep params serializable; register a client wrapper component if the preset uses functions, Pixi textures, or other client-only objects.

4. Displaying Custom Component Animations

On a Player

Use the showComponentAnimation method. On a client sprite, it returns a promise that resolves when the component animation calls onFinish.
Examples:
For a spritesheet animation on the same sprite, use showAnimation():
Server-side methods such as player.showComponentAnimation() and map.showComponentAnimation() only send the animation request to clients and remain fire-and-forget.

On a Map

Use the showComponentAnimation method on the map:
Examples:

Best Practices

1. Animation Performance

  • Keep spritesheet sizes reasonable (max 2048x2048)
  • Limit the number of simultaneous animations
  • Use onFinish callback to properly clean up component animations

2. Parameter Validation

Always provide default values for component parameters:

3. Memory Management

Component animations are automatically cleaned up when onFinish is called. Always call this callback when your animation completes: