Hi there,
I have looked at the tutorial on movement (No#4) and also this:
http://www.irrlicht3d.org/wiki/index.ph ... ntReceiver
on bool keys type stuff.
But currently there are a few things I don't understand:
1. Often with the other postings on using bool keys, it seems the state of the key (up/down/pressed/released) is being checked in the IEventReceiver OnEvent method or whatever, but then where are the retreived states stored in the bool array actually used? Are they used in the:
while(device->run()) { ... }
loop?
Or reused in the OnEvent handler? But shouldn't you use some kind of game timing rather than just an keypress detector method?
2. How does ensure the 3D object being moved does so in a consistant timed way? Use an ITimer object or something?
3. Currently I have it all just done from the OnEvent method, changing the position of my 3D object, etc. When I first press the "Left" key and hold it, first the 3D object moves to the left a unit, then pauses a bit, then realizes the key is still held down and continues to move. Why does it have to pause? How to get around that?
Also as a side note, I was a bit confused trying to read the API documentation, and couldn't find anything on the beginScene thing or the SColor thing? Where do I find info on those to learn more?
Thanks,
SD.
What is the correct way to handle keyboard input?
Re: What is the correct way to handle keyboard input?
Yes, usually you'd check MyEventReceiver->AllKeys[KEY_KEY_WHATEVER] in your game loop.sd wrote: 1. Often with the other postings on using bool keys, it seems the state of the key (up/down/pressed/released) is being checked in the IEventReceiver OnEvent method or whatever, but then where are the retreived states stored in the bool array actually used? Are they used in the:
while(device->run()) { ... }
loop?
Yes, store the time at the last loop (device->getTimer()->getTime()), and use the difference to work out how far you should move the actor (distance=direction*time)sd wrote:2. How does ensure the 3D object being moved does so in a consistant timed way? Use an ITimer object or something?
There's no way to get around this when the movement code is inside your event receiver. Your event receiver code is called when a key is pressed or released, you need to move your actors every frame, if a key is pressed.sd wrote:3. Currently I have it all just done from the OnEvent method, changing the position of my 3D object, etc. When I first press the "Left" key and hold it, first the 3D object moves to the left a unit, then pauses a bit, then realizes the key is still held down and continues to move. Why does it have to pause? How to get around that?
beginScene is called at the start of a render loop before drawing anything, SColor is just how the engine holds colours. Which part is confusing you?sd wrote: Also as a side note, I was a bit confused trying to read the API documentation, and couldn't find anything on the beginScene thing or the SColor thing? Where do I find info on those to learn more?
Excellent help, thankyou =)
Thanks, that answers my questions and seems to be just what I was looking for =). Seems I didn't look hard enough into the API docs to find those functions.
Thanks,
SD.
Thanks,
SD.
Re: What is the correct way to handle keyboard input?
Try understanding the code posted below...sd wrote: 3. Currently I have it all just done from the OnEvent method, changing the position of my 3D object, etc. When I first press the "Left" key and hold it, first the 3D object moves to the left a unit, then pauses a bit, then realizes the key is still held down and continues to move. Why does it have to pause? How to get around that?
Thanks,
SD.
Code: Select all
bool CCameraActorFPSSceneNode::OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
const u32 cnt = KeyMap.size();
for (u32 i=0; i<cnt; ++i)
{
if (KeyMap[i].keycode == event.KeyInput.Key)
{
CursorKeys[KeyMap[i].action] = event.KeyInput.PressedDown;
actionState = KeyMap[i].action;
if ( actionState != oldActionState )
{
if ( event.KeyInput.PressedDown )
{
if ( actionState == 0 )
{
nodeActor->setFrameLoop(1,14);
}
if ( actionState == 2 || actionState == 3 )
{
nodeActor->setFrameLoop(15,30);
}
}
else
{
//nodeActor->setFrameLoop(184,205);
nodeActor->setFrameLoop(206,250);
}
oldActionState = actionState;
}
else
{
if ( event.KeyInput.PressedDown == false )
{
//nodeActor->setFrameLoop(184,205);
nodeActor->setFrameLoop(206,250);
oldActionState = -1;
}
}
if ( InputReceiverEnabled )
return true;
}
}
actionState = -1;
if ( actionState != oldActionState )
{
if ( actionState = -1 )
{
//nodeActor->setFrameLoop(184,205);
nodeActor->setFrameLoop(206,250);
}
oldActionState = actionState;
}
}
return false;
}

