Class TRepoSoundEngine
Unit
Declaration
type TRepoSoundEngine = class(TSoundEngine)
Description
Sound engine that keeps a repository of sounds, defined in a nice XML file. This allows to have simple Sound and Sound3D methods, that take a sound identifier (managing sound buffers will just happen automatically under the hood).
It extends TSoundEngine, so you can always still load new buffers and play them by TSoundEngine.LoadBuffer, TSoundEngine.PlaySound and all other methods. This only adds easy preloaded sounds, but you're not limited to them.
To initialize your sounds repository, you have to set the RepositoryURL property.
Hierarchy
- TObject
- TSoundAllocator
- TSoundEngine
- TRepoSoundEngine
Overview
Methods
constructor Create; |
|
destructor Destroy; override; |
|
procedure LoadFromConfig(const Config: TCastleConfig); override; deprecated 'load sound properties explicitly from UserConfig'; |
|
procedure SaveToConfig(const Config: TCastleConfig); override; deprecated 'save sound properties explicitly to UserConfig'; |
|
procedure ReloadSounds; |
|
function SoundFromName(const SoundName: string; const Required: boolean = true): TCastleSound; |
|
procedure AddSoundImportanceName(const Name: string; Importance: Integer); deprecated 'use Priority, with numeric values'; |
|
procedure PrepareResources; |
Properties
property RepositoryURL: string read FRepositoryURL write SetRepositoryURL; |
|
property SoundsFileName: string read FRepositoryURL write SetRepositoryURL; deprecated 'use RepositoryURL'; |
|
property SoundImportanceNames: TStringList read FSoundImportanceNames; deprecated 'use Priority, with numeric values'; |
|
property MusicPlayer: TLoopingChannel read GetMusicPlayer; deprecated 'use LoopingChannel[0]'; |
|
property LoopingChannel [constIndex:Cardinal]: TLoopingChannel
read GetLoopingChannel; |
Description
Methods
constructor Create; |
|
destructor Destroy; override; |
|
procedure LoadFromConfig(const Config: TCastleConfig); override; deprecated 'load sound properties explicitly from UserConfig'; |
|
Warning: this symbol is deprecated: load sound properties explicitly from UserConfig |
procedure SaveToConfig(const Config: TCastleConfig); override; deprecated 'save sound properties explicitly to UserConfig'; |
|
Warning: this symbol is deprecated: save sound properties explicitly to UserConfig |
procedure ReloadSounds; |
|
Reload the RepositoryURL and all referenced buffers. Useful as a tool for game designers, to reload the sounds XML file without restarting the game and sound engine. |
function SoundFromName(const SoundName: string; const Required: boolean = true): TCastleSound; |
|
Return sound with given name. Available names are given in SoundNames, defined in XML file pointed by RepositoryURL. Always for SoundName = '' it will return nil. Parameters
|
procedure AddSoundImportanceName(const Name: string; Importance: Integer); deprecated 'use Priority, with numeric values'; |
|
Warning: this symbol is deprecated: use Priority, with numeric values |
procedure PrepareResources; |
|
Opens sound context and loads sound files, but only if RepositoryURL was set and contains some sounds. The idea is that you can call this during "loading" stage for any game that *possibly but not necessarily* uses sound. If a game doesn't use sound, this does nothing (doesn't waste time to even initialize sound context, which on some systems may cause some warnings). If a game uses sound (through RepositoryURL), this will initialize sound backend and load these sound files, to play them without any delay in game. Note that, if this does nothing, but you later set RepositoryURL or do LoadBuffer or Play, then sound context will be created on-demand anyway. So calling this is always optional. |
Properties
property RepositoryURL: string read FRepositoryURL write SetRepositoryURL; |
|
The XML file that contains description of your sounds. This should be an URL (in simple cases, just a filename) pointing to an XML file describing your sounds. See https://castle-engine.io/creating_data_sound.php and engine examples for details ( When you set When the sound context is initialized (or when you set this property, if the sound context is initialized already) then sound buffers will actually be loaded. If this is empty (the default), then no sounds are loaded, and TRepoSoundEngine doesn't really give you much above standard TSoundEngine. If you want to actually use TRepoSoundEngine features (like the Sound and Sound3D methods) you have to set this property. For example like this: SoundEngine.RepositoryURL := 'castle-data:/sounds.xml'; MySound1 := SoundEngine.SoundFromName('my_sound_1'); MySound2 := SoundEngine.SoundFromName('my_sound_2'); // ... and later in your game you can do stuff like this: SoundEngine.Play(MySound1);
See https://castle-engine.io/manual_data_directory.php for information about the castle-data:/ protocol. In short, on desktop, this just indicates the "data" subdirectory of your project. |
property SoundsFileName: string read FRepositoryURL write SetRepositoryURL; deprecated 'use RepositoryURL'; |
|
Warning: this symbol is deprecated: use RepositoryURL Deprecated name for RepositoryURL. |
property SoundImportanceNames: TStringList read FSoundImportanceNames; deprecated 'use Priority, with numeric values'; |
|
Warning: this symbol is deprecated: use Priority, with numeric values Sound importance names and values. Each item is a name (as a string) and a value (that is stored in Objects property of the item as a pointer; add new importances by AddSoundImportanceName for comfort). These can be used within sounds.xml file. Before using ContextOpen, you can fill this list with values. Initially, it contains a couple of useful values (ordered here from most to least important):
|
property MusicPlayer: TLoopingChannel read GetMusicPlayer; deprecated 'use LoopingChannel[0]'; |
|
Warning: this symbol is deprecated: use LoopingChannel[0]
Comfortable way to play and control the music. Simply assign MusicPlayer.Sound to play music. Set it to |
property LoopingChannel [constIndex:Cardinal]: TLoopingChannel
read GetLoopingChannel; |
|
Comfortable way to play and control looping non-spatial sounds, like music tracks, ambience. The TLoopingChannel instance automatically remembers the sound it plays. You start playing just by setting TLoopingChannel.Sound to some sound. For example: LoopingChannel[0].Sound := MyMusicTrack;
You stop by setting TLoopingChannel.Sound to something else, which can be LoopingChannel[0].Sound := nil;
Each channel has it's own TLoopingChannel.Volume that can be changed at any point. All the looping channels play simultaneously. Note: Alternative way to play looping non-spatial sounds is to use Play with TCastlePlayingSound (setting TCastlePlayingSound.Loop to |
Generated by PasDoc 0.16.0.