Using sounds collection (.castle-components file) play sound when user presses some key, using our view events.ĥ. In a real situation, you want to use such code to play sound inside a larger CGE application, e.g. NOTE: simplest_play_sound example is literally the simplest application that only plays a sound, without displaying anything. See source code of examples/audio/simplest_play_sound/simplest_play_sound.dpr for a working simplest possible example of this. Initialize the variable and load sound file, e.g. Load a sound file as TCastleSound like this:Īdd CastleSoundEngine to your uses clause.ĭeclare variable to hold it like MySound: TCastleSound Sound volume, and "auto-mute on play" are available in the editor settings.ĭrag-and-drop sound files on the viewport to automatically create a spatial sound: TCastleTransform, TCastleSoundSource, TCastleSound. See also examples/platformer as a demo how to design a collection of sounds (see below for details). It's a simple example of how TCastleSoundSource and TCastleSound can be set up in the CGE editor. In particular open the examples/audio/game_3d_sound demo. See all the examples in examples/audio subdirectory. You can also create and control them from code, as all CGE components. You can hear the 3D sounds in the editor. TCastlePlayingSound: Optional, use if you need more control before and during the sound playback.īoth TCastleSoundSource and TCastleSound can be created, configured and linked in the CGE editor, e.g. This way TCastleSoundSource can play multiple sounds at the same time. You can pass any TCastleSound or even your own TCastlePlayingSound to observe the playback. Play a sound calling TCastleSoundSource.Play. Turn it on or off using TCastleSoundSource.SoundPlaying. The sound source will play it automatically. Set a looping sound in TCastleSoundSource.Sound. TCastleSoundSource refers to TCastleSound for an actual sound information. This is a behavior that enhances any TCastleTransform so that it emits (possibly spatial) sounds. TCastleSoundSource: A way to play spatial (3D) sounds. You have to use SoundEngine.Play to play the sound (the simplest way to play, for non-spatial sounds) or TCastleSoundSource (for sounds that can be spatial assign to TCastleSoundSource.Sound for looping, use TCastleSoundSource.Play for non-looping). TCastleSound by itself doesn't manage playing the sound. As with volume, the volume of TCastleSound.Pitch is multiplied by similar parameters controlled at TCastlePlayingSound.Pitch and TCastleSoundSource.Pitch. This is multiplied by volume at TCastlePlayingSound.Volume and TCastleSoundSource.Volume and by spatial calculations. Stream - optionally use "streaming", which is an alternative loading method best suited for longer playing sounds (like music tracks). URL - undoubtedly the most important property, set this to actually load the sound file. This is a non-visual component that represents a sound file with some playback parameters. TCastleSound: The most important class, you should use this always when you want to play any sound. The most important classes and their usage Using sounds collection (.castle-components file)ġ.The most important classes and their usage.
0 Comments
Leave a Reply. |