Jump to content
  • Advertisement
Sign in to follow this  
bigbrother2000

C++/DirectX Trying to get a sound to play when moving an object?

This topic is 4908 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, i have a directX project and would like to loop a sound when my object is moving, and then pausing it when it is still. I am using this code although cannot find where to put my play sound line for it to play at the right place. At the moment the sound loops continuously when the object is still rather than when it is moving, any ideas? Dir = 0; if(m_Keyboard.GetKeyState(KEY_RIGHT) == TRUE) Dir |= 1; if(m_Keyboard.GetKeyState(KEY_UP) == TRUE) Dir |= 2; if(m_Keyboard.GetKeyState(KEY_LEFT) == TRUE) Dir |= 4; if(m_Keyboard.GetKeyState(KEY_DOWN) == TRUE) Dir |= 8; XMove = ZMove = 0.0f; if(Dir) { MoveAngle = Angles[Dir] + m_Camera.GetYRotation(); //playsound m_SndChannel[2].Play("..\\Data\\Earthslow.wav", 100, 0); float Speed = (float)Elapsed / 1000.0f * 384.0f; XMove = (float)sin(MoveAngle) * Speed; ZMove = (float)cos(MoveAngle) * Speed; // Change animation and check triggers if(XMove != 0.0f || ZMove != 0.0f) { if(LastAnim != 0) { LastAnim = 0; m_CharacterObject.SetAnimation(&m_CharacterAnim, "Walk", timeGetTime() / 20); } // Trigger showing map if any triggers hit } } else { // Change animation to idle if(LastAnim != 1) { LastAnim = 1; m_CharacterObject.SetAnimation(&m_CharacterAnim, "Idle", timeGetTime() / 20); } }

Share this post


Link to post
Share on other sites
Advertisement
Try change this:

m_SndChannel[2].Play("..\\Data\\Earthslow.wav", 100, 0);


to:

if (Dir!=0) m_SndChannel[2].Play("..\\Data\\Earthslow.wav", 100, 0);



Perhaps you just don't know enough programming yet or I'm too stupid to understand your problem, but this means "only play if you move".

Another problem might be if you press a key and hold it down so it repeats, the sample will start over again each time the key repeats (making stupid noise perhaps).

Anyway, good luck.

albert

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!