program HowToPlaySoundEffect; uses SwinGame; procedure Main(); begin OpenAudio(); OpenGraphicsWindow('How To Play Sound Effect' ,320 ,240 ); LoadDefaultColors(); ClearScreen(ColorWhite ); LoadSoundEffect('chipmunk.ogg' ); PlaySoundEffect('chipmunk.ogg' ); DrawText('How To Play Sound Effect!!!' ,ColorRed ,10 ,120 ); RefreshScreen(); Delay(5000 ); CloseAudio(); ReleaseAllResources(); end; begin Main(); end.
How To Play Sound Effect
This how to shows you how to play a sound effect in SwinGame. A sound effect is different to playing music. A sound effect will play over multiple channels which means you can play multiple sound effects simultaneously. Sound effects can be useful for giving the user feedback like a sound if a button is pressed, or when an event has completed.
To play a sound effect you must load it into the game loop. Sounds are stored in the Resources/sounds sub folder
The simplest method to play a sound effect is to Load Sound Effect('...') then call Play Sound Effect('...'). You notice we are using the file name as the name of the effect to play.
To keep track and reuse sound effects without having to reload them each time you may choose to load the sound effect into a variable, like this:
myEffect equals Load Sound Effect('...') then call:
Play Sound Effect(myEffect).
This way myEffect can be used each time you need to play the effect without needing to load it every time.
Under Windows a window need to be open in order for it to play audio
- Create special sound effect in game such as explosion, bullet flying.
- Interactivity between player and in game object using sound effect.