Keyboard Input - Smooth And Multiple keypress

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
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Keyboard Input - Smooth And Multiple keypress

Post by ktyrer496 »

hi,

Im trying to make a ship move, and i need it to move smoothly, but now it move one bit at a time and looks really silly and bad, like a jerking motion. also how can i make it so i can press more than one key at a time so that the ship can move diagnally rather than just left then up etc..

my code is as follows:

class MyEventReceiver : public IEventReceiver
{
public:
//============================================CONTROLS================================================
virtual bool OnEvent(SEvent event)
{
if (event.KeyInput.Key == KEY_KEY_A)
{
core::vector3df v = Munch->getPosition();
v.X += -2.0f;
Munch->setPosition(v);
}
return true;
}
};
//=============================================CONTROLS END=============================================

Any help would be appreciated

regards
The idea of war is not to die for your country, but to make the other bastard die for his!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Search for bool keys, or click one of the links below...

The gist of it is that you just capture the key states in the event receiver. When a key is pressed down you set a flag, and when it is released, you clear the flag. Then, in the game loop, you check the state of the keys and do something based on their status.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=25813
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=17033
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=19657
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=25517

Travis
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

If you download the latest SVN version, example 04.Movement has been updated to demonstrate storing key states.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Yup. The first link in that list is to the patch you posted last week.

Travis
Post Reply