Skip to main content
GameDev.net gamedev.net
🔒 Locked

Playing Sound problem

Started by 123abcd1983 Mar 1, 2007 at 12:35 AM 0 replies 400+ views
Original Post
123abcd1983
123abcd1983
I have some problem about playing the sound of button. I want to create some OnMouseOver event to my mouse button, because directX don’t support this so I do it in this way, when the mouse cursor point to position of the button on the screen, the button sound will play(like the code below). But I have some problem about this, when the mouse over the button the sound will keep continuing playing non stop, I think it’s because I play the sound inside the onframerender, so everytime the frame render then same sound file will play agains and agains. Anyone could help me solve this problem please.
Quote:
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime ) { if( cursorPoint.x >= CX_SCREEN*3/4 && cursorPoint.x <= CX_SCREEN*19/20 ) { if( cursorPoint.y >= CY_SCREEN/2 && cursorPoint.y < CY_SCREEN*5/ 8) { onButtonSound(onStartButton); } } }
Quote:
void onButtonSound(int button) { TCHAR strFileName1[MAX_PATH] = TEXT("start.wav"); g_pButtonSoundManager = new CSoundManager(); g_pButtonSoundManager->Initialize( hwnd,DSSCL_PRIORITY); if (button == onStartButton) { g_pButtonSoundManager->Create( &g_pButtonSound, strFileName1, 0, GUID_NULL,1 ); break; } g_pButtonSound->Play( 0, 0); g_pButtonSound->Reset(); g_pButtonSound = NULL; g_pButtonSoundManager = NULL; }
Endurion
Endurion
Simple solution:

You need to remember which control the mouse is in. Only if the mouse is inside a control and the remembered control is different from the current control you play the sound.

After that check set the remembered control to the current one.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.