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.
Axel186
Posts: 15 Joined: Thu May 24, 2007 2:54 pm
Location: Israel
Post
by Axel186 » Thu May 31, 2007 4:43 pm
Have a problem with pushing on two keys and make 2 actions...
I want that my car will move and rotate, the car moving on keys W,S and rotating on A,D. If I push on one of this keys everything OK, but when I push on 2 keys only one action done...
That's my source:
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
return true;
}
return false;
}
};
//Actions function
void ProcessInput()
{
if(keys[irr::KEY_KEY_W])
Speed=Speed+0.05;
if(keys[irr::KEY_KEY_S])
Speed=Speed-0.05;
if(keys[irr::KEY_KEY_A])
rotY=rotY-Speed;
if(keys[irr::KEY_KEY_D])
rotY=rotY+Speed;
if(keys[irr::KEY_SPACE])
Speed=Speed*0.8;
}
PLZ help!
Perceval
Posts: 158 Joined: Tue May 30, 2006 2:42 pm
Post
by Perceval » Thu May 31, 2007 5:27 pm
You're initialising your keys[] tab each time you call onEvent(). You have to initialise it once, in the constructor. So your onEvent() function become (there was some useless code) :
Code: Select all
virtual bool OnEvent(SEvent event)
{
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
return false;
}
and your constructor :
Code: Select all
MyEventReceiver()
{
int i = 0;
for (i = 0; i < irr::KEY_KEY_CODES_COUNT; i++)
Keys[i] = false;
}
Axel186
Posts: 15 Joined: Thu May 24, 2007 2:54 pm
Location: Israel
Post
by Axel186 » Thu May 31, 2007 7:15 pm
Thank you very much !!! =)) It's great!