Display Animations
This guide explains how to display animations in RPG-JS. There are two main 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
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.1. Creating a Custom Animation Component
Create a Canvas Engine component file (e.g.,ExplosionComponent.ce):
2. Registering the Component Animation
Add your component to the module configuration:3. Displaying Custom Component Animations
On a Player
Use theshowComponentAnimation method:
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: