which event for key pressed and hold

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

which event for key pressed and hold

Post by blackMasoon »

Hello. I want to implement sound of walking in my event method. For that i need to receive an event of pressed and hold key to play irrklang sound? which event shall I choose instead of irr::KEY_XX (XX means type of key).

I need that because if i try to do this:

Code: Select all

if(pManager->getKey(irr::KEY_UP) || pManager->getKey(irr::KEY_DOWN) || pManager->getKey(irr::KEY_LEFT) || pManager->getKey(irr::KEY_DOWN))
		getMySoundEngine()->play2D("media/sounds/grasswalk.wav",false);
it starts to ply sound many times.
MPKaboose
Posts: 6
Joined: Tue Jun 22, 2010 5:15 pm

Post by MPKaboose »

my suggestion would be that when the key is pressed apply the playing of the sound once then when the key is not held down stop it (once) sorry if I exprime myself bad
nathanf534
Posts: 199
Joined: Tue Dec 09, 2008 2:55 am

Post by nathanf534 »

you need to use some boolean variable to remember if the key is up/down

this might be what you want

Code: Select all

bool keyDown=false;
bool playingSound=false;
if(pManager->getKey(irr::KEY_UP) || pManager->getKey(irr::KEY_DOWN) || pManager->getKey(irr::KEY_LEFT) || pManager->getKey(irr::KEY_DOWN)) 
      keyDown=true;
if(keyDown&&!playingSound){
    getMySoundEngine()->play2D("media/sounds/grasswalk.wav",false);
    playingSound=true;
}

Im not entirely sure how your sound engine works... so you will need to add something that either stops the sound, or makes it repeat when its over...
while(signatureEmpty){cout<<wittyComment();}
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

blackMasoon,

I think you have to do:

Code: Select all

- if sound key pressed:
    - if sound not playing
        - start play sound
        - else do nothing
p.s.: the sound should be short (like 1.0-1.5 seconds).
blackMasoon
Posts: 149
Joined: Wed Sep 09, 2009 4:57 pm
Contact:

Post by blackMasoon »

Thanks guys but i found a soundsource bool method called isCurrentlyPlaying() which does all the work ;)
Post Reply