Hey Matty,
not sure if this helps but here's how you could have either Looping Music sound files play when you want or not, nothing major big, just loading the two sound files, pausing them at the start, then when you hit a key it resumes the play looping of the sound, but as you'll see it resumes right where it left off, and not starting over:
But what I would recommend for more control is this little piece of code that allows you more control over playing sounds either by themself or mixed together. You could have music playing in the background while other sounds like Menu Clicks and such could be heard.
To use the Functions load in your sound files ahead of time:
To Play a sound and/or loop:
-1 Means only play the once once until asked to play again or Simultaneous Off
1 Mean Play the sound as many times as asked for, like if your shooting a gun over and over and the sound overlay eachother.
Well not sure if this helps and but my 3 cents worth.
Topknot ;)
not sure if this helps but here's how you could have either Looping Music sound files play when you want or not, nothing major big, just loading the two sound files, pausing them at the start, then when you hit a key it resumes the play looping of the sound, but as you'll see it resumes right where it left off, and not starting over:
; Load Sounds soundhandle1 = LoadSound("C:\windows\media\Windows XP Startup.wav") soundhandle2 = LoadSound("C:\windows\media\Windows XP Shutdown.wav") ; Set them to Looping LoopSound soundhandle1 LoopSound soundhandle2 ; Assign each sound file to a channel soundchn1 = PlaySound(soundhandle1) soundchn2 = PlaySound(soundhandle2) ; Pause BOTH channels for now PauseChannel soundchn1 PauseChannel soundchn2 While Not KeyHit(1) ; Hit 1 to play Sound Loop 1 If KeyHit(2) ResumeChannel soundchn1 EndIf ; Hit 2 to play Sound Loop 2 If KeyHit(3) ResumeChannel soundchn2 EndIf ; To Stop Both Channels hit SPACE If KeyHit(57) PauseChannel soundchn1 PauseChannel soundchn2 EndIf Wend End
But what I would recommend for more control is this little piece of code that allows you more control over playing sounds either by themself or mixed together. You could have music playing in the background while other sounds like Menu Clicks and such could be heard.
; ################################################################################################### ; # Play Sound Bites and Samples as Needed # ; ################################################################################################### Type ActiveChannel Field SampleID% Field Address% Field Pitch% End Type Function PlaySample ( SampleAddress% , SampleID% );= -1 ) Local Channel.ActiveChannel Local Simultaneous% = False Local Playing% = False If SampleID < 0 Then Simultaneous = True For Channel = Each ActiveChannel If Channel\SampleID = SampleID Then Playing = True If Not ChannelPlaying ( Channel\Address ) Then Delete Channel Next If Not ( Simultaneous = False And Playing = True ) Channel = New ActiveChannel Channel\SampleID = SampleID Channel\Address = PlaySound ( SampleAddress ) EndIf End Function Function UpdateChannels () Local Channel.ActiveChannel For Channel = Each ActiveChannel If Not ChannelPlaying ( Channel\Address ) Then Delete Channel Next End Function Function SoundOff () ; Force a 'Sound Off' (a variation of UpdateChannels) Local Channel.ActiveChannel ; Channel cursor For Channel = Each ActiveChannel ; Iterate through channels StopChannel Channel\Address ; Stop playing Delete Channel ; Remove channel from active channels Next End Function
To use the Functions load in your sound files ahead of time:
Global Sound1 = LoadSound("soundfile1.wav") Global Sound2 = LoadSound("soundfile2.wav")
To Play a sound and/or loop:
PlaySample (Sound1,-1) PlaySample (Sound2,1)
-1 Means only play the once once until asked to play again or Simultaneous Off
1 Mean Play the sound as many times as asked for, like if your shooting a gun over and over and the sound overlay eachother.
Well not sure if this helps and but my 3 cents worth.
Topknot ;)