Display Animations
This guide explains how to display animations in RPG-JS. There are three common types of animations you can create and display:- Spritesheet Animations - Using image spritesheets with the built-in animation system
- Custom Component Animations - Creating your own Canvas Engine components for complex effects
- CanvasEngine FX Animations - Using the prebuilt
Fxcomponent animation for particle effects
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-inAnimationSpritesheetPreset helper:
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 theshowAnimation method on a player instance:
On a Map
Use theshowAnimation method on a map instance:
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()receivedataandparams - component animations rendered with
showComponentAnimation()receive their props directly (x,y,onFinish, and your custom params)
componentAnimations, not for custom map scene components.1. Creating a Custom Animation Component
Create a Canvas Engine component file (e.g.,ExplosionComponent.ce):
draw-map.ce:
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 CanvasEngineFx preset system. Register it like any other component animation:
showComponentAnimation() and pass CanvasEngine Fx props:
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:
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 theshowComponentAnimation method. On a client sprite, it returns a
promise that resolves when the component animation calls onFinish.
showAnimation():
player.showComponentAnimation() and
map.showComponentAnimation() only send the animation request to clients and
remain fire-and-forget.
On a Map
Use theshowComponentAnimation method on the map:
Best Practices
1. Animation Performance
- Keep spritesheet sizes reasonable (max 2048x2048)
- Limit the number of simultaneous animations
- Use
onFinishcallback 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 whenonFinish is called. Always call this callback when your animation completes: