problem is that it checks for "PressedDown" so that's why the song stops and resumes several times when you press the space key once. Is there an easy way to check for a single Key Press?
I already tried to extract this very feature from IrrEventManager, but didn't succeed; and I do not want to use the entire manager since actually there is only this one thing I need.
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
{
if (!event.KeyInput.PressedDown)
{
switch (event.KeyInput.Key)
{
case irr::KEY_ESCAPE: /* do stuff only when ESC key is left up*/ return true;
default: break;
}
}
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
}
As you can see, you need to handle such cases differently. And you should use the EKEY_CODE enum.
one last question on this:
it plays/stops when the key is left up. at the moment that's good enough for me but I think it might feel a lil better if it triggers on keydown. how much more complicated would it be?
Basically what you need to do is, instead of starting/stopping the music from playing when the button is released, you make it stop/play when it is pressed down, but first check whether it was pressed down already before doing it. If it wasnt then set your keys variable that it's down, and do the action, or if it was down already then do nothing. Then when you let go, set your keys variable so that it isn't being held down any more, so that it will work again the next time you press it.
class EventReceiver : public IEventReceiver
{
private:
bool KeyIsDown[KEY_KEY_CODES_COUNT];
s32 keyState[KEY_KEY_CODES_COUNT];
s32 LMouseState,RMouseState;
public:
//constrctor
EventReceiver();
//destructor
virtual ~EventReceiver();
//onEvent from Irrlicht
virtual bool OnEvent(const SEvent &event);
//isKeyDown From Irrlicht
virtual bool IsKeyDown(EKEY_CODE keyCode) const;
//used for see mouse down & drag
void tick();
//reset the receiver
void reset();
// return true is left mouse down
bool isMouseLeftDown();
//return true is rightmouse down
bool isMouseRightDown();
//return true is left mouse is up after press down
bool isMouseLeftUp();
//return true if right mouse is up after press down
bool isMouseRightUp();
//return true if left mouse is in drag state
bool isMouseLeftDrag();
// return true if right mouse is in drag state
bool isMouseRightDrag();
//return true if the left mouse is not in any action
bool isMouseLeftIdle();
//return true if the right mouse is not in any action
bool isMouseRightIdle();
//return true if the key pressed down
bool isKeyPress(EKEY_CODE keyCode);
//return true if the key is up after press down
bool isKeyUp(EKEY_CODE keyCode);
};
in the main loop add receiver->tick(); before the end of main loop..
hope this can help you
hai adik2 semua mari kita belajar sambil bermain bersama saya si BOBBY BOLA di edugames bermacam pelajaran bisa didapat ad berhitung menggambar mewarnai tidak ketinggalan dapat belajar nyanyi juga belajar huruf angka & logika bersama BOBBY BOLA semua bisa