Animated Sprite
The AnimatedSprite class in dill-pixel extends Pixi.js’s AnimatedSprite to provide a more game-friendly implementation for frame-based animations. It’s particularly useful for sprite sheets containing multiple animations for a single character or object.
See the Animated Sprites
scene in the examples:
Demo | Source
for a practical implementation.
Key Features
- Simplified Configuration
- Animation Management
- Built-in support for multiple named animations
- Easy switching between animations using
nextAnimation()
andpreviousAnimation()
- Per-animation speed configuration
- Automatic texture generation from sprite sheets
- Enhanced Control
- Pause/resume functionality
- Animation reversal support
- Rich event system for animation states
Differences from Pixi.js AnimatedSprite
- Configuration
- Pixi.js: Requires manual texture array creation
- dill-pixel: Handles texture generation automatically from configuration
- Animation Management
- Pixi.js: Has basic play/stop functionality
- dill-pixel adds:
- Named animations
- Animation switching
- Per-animation speeds
- Reverse playback
- Pause/resume
- Rich event system using signals
- Event System
- dill-pixel adds additional signals:
onAnimationChange
onAnimationStart
onAnimationStop
onAnimationLoop
onAnimationComplete
onAnimationFrameChange
- dill-pixel adds additional signals:
Example Usage
The AnimatedSpriteScene demonstrates a practical implementation:
This configuration creates a character with multiple animations, each having different frame counts and speeds. The animations can be cycled through by clicking on the sprite:
Benefits Over Basic Pixi.js Implementation
- Automatic Asset Management
- Handles sprite sheet references
- Manages texture generation
- Supports zero-padding for frame numbers
- Game-Ready Features
- Built-in pause/resume
- Animation speed control
- Animation sequencing
- Reverse playback support
- Developer Experience
- Declarative configuration
- Simplified API
- Robust event system
- Automatic cleanup