I'm trying to understand sounds using Monkey+Diddy. When I attempt to add a sound to the GUI example, I get this error:
I've added four lines to the GUI example and have added the sounds/drum.wav file in testGUI.data.
Here's the code (only showing parts I changed):
Class MyGame extends DiddyApp
Method OnCreate:Int()
Super.OnCreate()
images.Load("button.png", "", False)
images.Load("buttonClick.png", "", False)
images.Load("check.png", "", False)
images.Load("checkClick.png", "", False)
sounds.Load("drum.wav") ' load the sound
drawFPSOn = True
guiScreen = new GUIScreen
guiScreen.PreStart()
return 0
End
End
Class MyGUI Extends GUI
Field button:Button
Field toggleButton:Button
Field slider:Slider
Field buttonImage:GameImage
Field drum:GameSound ' define the variable for the sound
Method New()
drum = game.sounds.Find("drum") ' get the sound
button = New Button(desktop, game.images.Find("button"), game.images.Find("buttonClick"))
button.SetBounds(150,50,100,50)
button.Text ("HELLO", 0.5, 0.5)
toggleButton = New Button(desktop, game.images.Find("check"))
toggleButton.toggle = True
toggleButton.SetBounds(50,120,100,50)
toggleButton.StyleSelected.image = game.images.Find("checkClick")
toggleButton.StyleSelected.drawBackground = False
slider = New Slider(desktop)
slider.SetBounds(50,190,200,20)
slider.ShowButtons = True
slider.StyleNormal.red = 0
slider.StyleNormal.green = 0
slider.StyleNormal.blue = 255
End
Method ActionPerformed:Void(source:Component, action:String)
If source = slider And action = ACTION_VALUE_CHANGED Then
Print "slider="+Slider(source).value
ElseIf source = button And action = ACTION_CLICKED Then
Print("pressed button!")
drum.Play() ' play sound when button clicked
ElseIf source = toggleButton And action = ACTION_CLICKED Then
If toggleButton.selected Then
Print("pressed toggleButton! selected=true")
Else
Print("pressed toggleButton! selected=false")
End
End
End
End
If I comment out the drum.Play() line, no error occurs. So I figure everything's loaded up fine, it just can't play it from there.
|