Results 1 to 3 of 3

Thread: Sound Effects

  1. #1

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372

    Sound Effects

    Hi guys,

    I'm making up a pong game and I'm having trouble with the sounds. I want to be able to play a sound everytime the ball hits a wall. I'm using the following code:

    If BallX < 0 Then
    BallX = 0
    BallXDir = 1
    RtnValue = sndPlaySound(Bounce, SND_ASYNC Or SND_MEMORY)

    The sound has been stored here:

    Dim Buffer As String
    Dim F As Integer
    Dim SoundBuffer As String
    On Error GoTo NoiseGet_Error
    Buffer = Space(1024)
    SoundBuffer = ""
    F = FreeFile
    Open FileName For Binary As F
    Do While Not EOF(F)
    Get #F, , Buffer
    SoundBuffer = SoundBuffer & Buffer
    Loop
    Close F
    StoreSound = Trim(SoundBuffer)
    Exit Function
    NoiseGet_Error:
    SoundBuffer = ""
    Exit Function

    And in the form load:
    Bounce = StoreSound(App.Path + "Bounce.wav")

    I think I've declared everything I should:

    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Private Const SND_ASYNC = &H1
    Private Const SND_SYNC = &H0
    Private Const SND_MEMORY = &H4


    But the sound won't play. Can you see where I might have gone wrong? Maybe I left something out.

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    I would try changing it to somthing like this.
    VB Code:
    1. Option Explicit
    2. 'I think I've declared everything I should:
    3. Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    4. Private Const SND_ASYNC = &H1
    5. Private Const SND_SYNC = &H0
    6. Private Const SND_MEMORY = &H4
    7. Private Const SND_FILENAME = &H20000 '<==added
    8.  
    9. Dim strPath As String  '<==added
    10. Dim Bounce As String  '<===added
    11.  
    12. Private Sub Form_Load()
    13.     'And in the form load:
    14.     If Right(App.Path, 1) = "\" Then
    15.         strPath = App.Path
    16.     Else
    17.         strPath = App.Path & "\"
    18.     End If
    19.    
    20.     Bounce = strPath & "Bounce.wav"
    21. End Sub
    22.  
    23. '   In some procedure
    24. If BallX < 0 Then
    25.     BallX = 0
    26.     BallXDir = 1
    27.     'RtnValue = sndPlaySound(Bounce, SND_ASYNC Or SND_MEMORY)
    28.     RtnValue = sndPlaySound(Bounce, SND_FILENAME Or SND_ASYNC) '<===added
    29. End If

  3. #3

    Thread Starter
    Hyperactive Member GingerNut's Avatar
    Join Date
    May 2002
    Location
    Are those my feet?
    Posts
    372
    Works a treat!!!
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width