| 1 |
{ |
| 2 |
Copyright 2023-2023 Andrzej Kilijański, Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Manage the repository of sounds (useful from any view). |
| 17 |
|
| 18 |
Usage: |
| 19 |
- Configure sounds using CGE editor by editing sounds.castle-component , |
| 20 |
- From code: |
| 21 |
- Call once InitializeSounds (e.g. from ApplicationInitialize) |
| 22 |
- Use NamedSound to load TCastleSound instances. } |
| 23 |
unit GameSound; |
| 24 |
|
| 25 |
interface |
| 26 |
|
| 27 |
uses CastleSoundEngine; |
| 28 |
|
| 29 |
{ Initialize, call before any call to NamedSound. } |
| 30 |
procedure InitializeSounds; |
| 31 |
|
| 32 |
{ Returns TCastleSound with the given name from sounds.castle-component design. } |
| 33 |
function NamedSound(const Name: String): TCastleSound; |
| 34 |
|
| 35 |
implementation |
| 36 |
|
| 37 |
uses Classes, |
| 38 |
CastleWindow, CastleComponentSerialize; |
| 39 |
|
| 40 |
var |
| 41 |
{ Owner of components loaded from sounds.castle-component. } |
| 42 |
Sounds: TComponent; |
| 43 |
|
| 44 |
function NamedSound(const Name: String): TCastleSound; |
| 45 |
begin |
| 46 |
Result := Sounds.FindRequiredComponent(Name) as TCastleSound; |
| 47 |
end; |
| 48 |
|
| 49 |
procedure InitializeSounds; |
| 50 |
begin |
| 51 |
Sounds := TComponent.Create(Application); |
| 52 |
ComponentLoad('castle-data:/sounds.castle-component', Sounds); |
| 53 |
end; |
| 54 |
|
| 55 |
end. |