Captions
The captions system in dill-pixel provides synchronized subtitles/captions for voice-over audio content. It’s tightly integrated with the audio system and supports multiple languages, styling options, and positioning configurations.
Configuration
Captions can be configured in your dill-pixel.config.ts file. Here’s an example configuration:
Available Configuration Options
- Core Settings:
files
: Array of caption files for different languagesdefaultLocale
: Default language (defaults to ‘en’)enabled
: Whether captions are enabled (defaults to true)
- Visual Settings:
fontFile
: Path to the bitmap font filefontName
: Name of the font to usefontSizeMultiplier
: Scale factor for font sizemaxWidth
: Maximum width of captions (as ratio of screen width)textColor
: Color of caption textbackgroundColor
: Color of caption backgroundbackgroundAlpha
: Opacity of caption background
- Positioning Settings:
floating
: Whether captions float or stretch full width - distance: Distance from screen edge when floatingpadding
: Padding around caption textposition
: Vertical position (‘top’ or ‘bottom’)
Integration with Audio System
The CaptionsPlugin automatically syncs with the AudioManagerPlugin through several signal connections:
onLocaleChanged
: Triggered when the locale changesonVoiceOverStart
: Triggered when voiceover startsonVoiceOverPaused
: Triggered when voiceover is pausedonVoiceOverResumed
: Triggered when voiceover is resumedonVoiceOverComplete
: Triggered when voiceover completesonVoiceOverStopped
: Triggered when voiceover stops
These connections ensure captions are:
- Started when voice-over begins
- Paused/resumed with audio
- Stopped when voice-over ends
- Cleared when switching scenes
Caption Rendering
The CaptionsRenderer handles the visual presentation of captions.
Key rendering features:
- Bitmap text rendering for optimal performance
- Background sprite with configurable color/opacity
- Automatic text wrapping and positioning
- Smooth fade transitions
- Support for different screen sizes and orientations
Localization Support
The captions system integrates with the i18n system:
- Locale-specific caption files are loaded based on the current locale
- Captions are displayed in the selected language
- Captions are cleared when switching locales
Best Practices
- Caption Files: Structure your caption files with proper timing:
- Accessibility: Always provide clear contrast between text and background colors
- Positioning: Consider game content when choosing between top/bottom positioning
- Text Width: Keep maxWidth between 0.4-0.8 for optimal readability
Voiceover Integration
Captions in dill-pixel are be paired with voiceovers. See the Voiceover documentation for more information.