In the tutorials there is a movement example where you move a ball up or down using the keyboard. My trouble is I have removed the
!event.KeyInput.PressedDown
from the "if" statement to allow the ball to keep moving if you hold down the key.
What happens is the ball moves pauses and then keeps moving.
1) How do I remove the pause?
2) Movement of the ball is jumpy after the pause because of the space the ball is moving at each loop. If i shorten the spaced moved, movement is smoother but alot slower. How do you move nodes with the keyboard with out having jittery movement of the node?
ie when you move the camera with the keyboard it is smooth without hesitation unlike node in movement example.
Node Movement Hesitation
You may want to look at this post: http://irrlicht.sourceforge.net/phpBB2/ ... olean+keys
Or go to the bottom of http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16772 you can find there my MyEventReceiver class which do what you seek for. At last I think so
Or go to the bottom of http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16772 you can find there my MyEventReceiver class which do what you seek for. At last I think so
-
- Posts: 6
- Joined: Tue Nov 21, 2006 6:13 pm
the method you're using is for when someone types a key, this isn't what you want though. you need to move something each frame depending on whether the key is held down or not. that's how the keystate array helps you- do the movement each frame if they key is held down, not as each keypress event happens
-
- Posts: 6
- Joined: Tue Nov 21, 2006 6:13 pm
-
- Posts: 6
- Joined: Tue Nov 21, 2006 6:13 pm
Just in case anyone is new and found this thread I will post the modified source for main.cpp from the modified movement example
And then the changes to the game loop:
Code: Select all
//Add variables for key down state
bool skey_down = false;
bool wkey_down = false;
//also you could make these static members of the My event reciever and always have the current state of the key down where ever you have the object
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
wkey_down = event.KeyInput.PressedDown;
return true;
case KEY_KEY_S:
skey_down = event.KeyInput.PressedDown;
return true;
default:
return false;
}
}
return false;
}
};
Code: Select all
//this code should be inside main function
//replace code for the device->run() loop
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Movement Example - Irrlicht Engine [%ls] fps: %d",
driver->getName(), fps);
device->setWindowCaption(tmp);
lastFPS = fps;
}
if(wkey_down || skey_down)
{
core::vector3df v = node->getPosition();
v.Y += wkey_down > skey_down ? 0.1f : wkey_down == skey_down ? 0 : -0.1f;// if both are true then dont move
node->setPosition(v);
}
}