Debian Codegraph @

tools/castle-editor/data/project_templates/3d_fps_game/files/code/gamesound.pas

raw
1 { Manage the repository of sounds (useful from any view).
2
3 Usage:
4 - Configure sounds using CGE editor by editing sounds.castle-component ,
5 - From code:
6 - Call once InitializeSounds (e.g. from ApplicationInitialize)
7 - Use NamedSound to load TCastleSound instances.
8
9 Feel free to use this code as a starting point for your own projects.
10 This template code is in public domain, unlike most other CGE code which
11 is covered by BSD or LGPL (see https://castle-engine.io/license). }
12 unit GameSound;
13
14 interface
15
16 uses CastleSoundEngine;
17
18 { Initialize, call before any call to NamedSound. }
19 procedure InitializeSounds;
20
21 { Returns TCastleSound with the given name from sounds.castle-component design. }
22 function NamedSound(const Name: String): TCastleSound;
23
24 implementation
25
26 uses Classes,
27 CastleWindow, CastleComponentSerialize;
28
29 var
30 { Owner of components loaded from sounds.castle-component. }
31 Sounds: TComponent;
32
33 function NamedSound(const Name: String): TCastleSound;
34 begin
35 Result := Sounds.FindRequiredComponent(Name) as TCastleSound;
36 end;
37
38 procedure InitializeSounds;
39 begin
40 Sounds := TComponent.Create(Application);
41 ComponentLoad('castle-data:/sounds.castle-component', Sounds);
42 end;
43
44 end.