Playing Sound Issues...

Blitz3D Forums/Blitz3D Programming/Playing Sound Issues...

darklordz(Posted 2004) [#1]
Whils writing a small interface i kept having the following problem. I want a sound (ogg) to play once when mouse moving over a button object. Now playing the sound isn't the problem. It's getting the sound to play once. You see i have this structure set up for my buttons.

pseudocode
Button Type
CreateButton
GameLoop
UpdateButton
EndGameLoop
FreeButton


Now as you noticed the update button is called from within a loop and the update function looks like this...
	For A.BUTTON = Each BUTTON
		If MouseX() > A\XP% And MouseX() < A\XP% + ImageWidth(BTN_MENU%) And MouseY()>A\YP% And MouseY()<A\YP% + ImageHeight(BTN_MENU%) And MouseDown(1)=0
			A\STATE% = 1
			; <<<<<< PLAYSOUND HERE >>>>>>>>
		ElseIf MouseX() > A\XP% And MouseX() < A\XP% + ImageWidth(BTN_MENU%) And MouseY()>A\YP% And MouseY()<A\YP% + ImageHeight(BTN_MENU%) And MouseDown(1)=1
			MOUSEUP% = 1
			A\STATE% = 2
		Else
			A\STATE% = 0
		EndIf
		
		If MouseX() > A\XP% And MouseX() < A\XP% + ImageWidth(BTN_MENU%) And MouseY()>A\YP% And MouseY()<A\YP% + ImageHeight(BTN_MENU%) And MOUSEUP% = 1
			PlaySound SND_MNUD%
			Select A\ID%
				Case GAMEMENUPLAY%
					GAMEMODE% = GAMETYPEGAME%
			End Select
			MOUSEUP% = 0
		EndIf
		ButtonDraw(A\CAPTION$,A\XP%,A\YP%,A\STATE%)
	Next


notice where it says playsound there.... Thats where id add playsound <channel name> but it keeps playing it in a repetative way that maked it all distorted. How would i go abot playing it only once every new button id? (A\ID% == button id)


ford escort(Posted 2004) [#2]
just add a check to see if the mouse already played the sound on that button if not store the handle in the check variable

If mouseplayed<>BTN_MENU%
PlaySound SND_MNUD%
mouseplayed=BTN_MENU%
EndIf


darklordz(Posted 2004) [#3]
What i tough the solution would be was checking the current button's id, and if the A\ID <> CURRENT ID then play sound but even then i repeatatively plays the sound, this because the button update is within a typeloop within the mainloop! If it was in the main loop only there would be no problem. But since i NEED it to play from within the typeloop i have a problem....


jfk EO-11110(Posted 2004) [#4]
see? types are evil! I just gonna ask the congress for 80 billions for a "war against types".

explicit :P

why don't you simply use an array to check the buttons, and use a flipflop state variable for mouseover and mouseout. someting like
if mouseoverbutton
 if state=0
  playsound ding
  state=1
 endif
else
 if state=1
  playsound elvis_has_left_the_building
  state=0
 endif
endif



darklordz(Posted 2004) [#5]
Just a lil too late jfk, i just did that last night, thanks for the help....


eBusiness(Posted 2004) [#6]
DEATH TO THE TYPES!!! ATTACK!!!