Playing a lwav file as background music
Blitz3D Forums/Blitz3D Beginners Area/Playing a lwav file as background music
| ||
| Hi all. My game is getting there, now. I'm trying to play a 15-second wav file as background music for the attract mode, but, being stuck in the attract mode loop, it just plays all weird and loopy. Is there a way to call the sound file and set it off without hiding it in a loop? Cheers. |
| ||
I'm not sure what you mean by "weird and loopy", but I suspect that you might be calling PlaySound every time in your loop. Could that be it? Here's what should work:snd = LoadSound("soundfile.wav") ; <--- Do this ONCE at the beginning of the program, i.e. not in a loopAnd when the attract mode starts... Playsound(snd, 1) ; <--- Do this ONCE at the beginning of attract mode I'm also not sure what you mean by "setting of the sound file without hiding it in a loop"... If this doesn't work or you can't figure it out, perhaps you could post the basics of your code? |
| ||
| I was just writing this when Soja replied, I'll post it anyway if it helps.... cut and paste and put your sound file in....
Graphics 800,600
Global MySoundStarted = False
Global MyMusicLoop=LoadSound("YOUR SOUND HERE")
LoopSound MyMusicLoop
MyChannelSound=PlaySound(MyMusicLoop,2);flag set to pause
SetBuffer BackBuffer()
While Not KeyHit(1)
If KeyHit(31) Then
If MySoundStarted = False Then
ResumeChannel MyChannelSound
MySoundStarted = True
Else
PauseChannel MyChannelSound
MySoundStarted = False
EndIf
EndIf
Text 30,280,"hit ESC to quit"
Text 30,300,"hit the S key to turn the sound on and off"
Flip
Wend
StopChannel MyChannelSound
FreeSound MyMusicLoop
End
|