I've followed the tutorial for movement, and that was all fine. However, I tweaked the code a bit. I attempted to gain steady movement by holding down a key, such as an arrow key.
After randomly guessing to check for KEY_KEY_UP, I noticed some odd behaviour. The box responded just like a word processor; accept the input once, pause, then repeat rapidly.
I don't want a word-processor-type input. I want simple on and off. I've done it before successfully in OpenGL. However, I don't want to write my programs to use a few Irrlicht commands in an OpenGL shell. (That might provide even more issues to deal with.) Could that be the only way? Or is there a simpler method of implementing digital keyboard input?
Keyboard Input types
Hmm.. What about this..?
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
/*
If the key 'W' or 'S' was left up, we get the position of the scene node,
and modify the Y coordinate a little bit. So if you press 'W', the node
moves up, and if you press 'S' it moves down.
*/
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}
return false;
}
};
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
/*
If the key 'W' or 'S' was left up, we get the position of the scene node,
and modify the Y coordinate a little bit. So if you press 'W', the node
moves up, and if you press 'S' it moves down.
*/
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}
return false;
}
};
BlueLight