An elegant way of doing this simple thing?

Blitz3D Forums/Blitz3D Beginners Area/An elegant way of doing this simple thing?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I would do something like...


Graphics 800,600
SetBuffer BackBuffer()

Const No_Sounds = 4

Dim Sounds(No_Sounds)

For loop = 1 to No_Sounds
   Sounds(loop) = LoadSound("sound"+loop+".wav")
Next

While Not KeyHit(1)
 
  Cls

  If KeyHit(2) then PlaySound(Sounds(1))
  If KeyHit(3) then PlaySound(Sounds(2))
  If KeyHit(4) then PlaySound(Sounds(3))
  If KeyHit(5) then PlaySound(Sounds(4))

  Flip
Wend
End



What you can do is do...


chn = PlaySound( sound)



And assign the playing sound to a channel. Then you can alter the playing sounds volume and panning. Your code at present is using a type collection to store these values, but there isn't much point unless you assign your playing sound to a channel. You might be better off, if this is the approach your taking, adding in a channel field, you can assign the sound whilst it's playing.

Your code whilst being propery written, isn't very simple to follow. Unless you need that kind of control over your code, you might be better off taking a simplier approach. Although, your loading method is good and will track down errors easily. Just my opinion of course :o)