Smooth input??

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
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Smooth input??

Post by twilight17 »

Ok, so I'm making a little Pong game as my intro to Irrlicht. I have set up an event receiver, and added 2 meshes. I have set the first mesh to move up when I press "W" and down when I press "S". It works, but it doesn't do it smoothly. I can't hold it down and keep it going either. Heres some of my code:

Event Receiver

Code: Select all

class MyEventReceiver : public IEventReceiver

{
public:
	virtual bool OnEvent(const SEvent& event)
	{
		if (P1node != 0 && event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_W:
				{
					vector3df P1up = P1node->getPosition();
					P1up.Y += event.KeyInput.Key == KEY_KEY_W ? 5.0f : -5.0f;
					P1node->setPosition(P1up);
					break;
				}
			case KEY_KEY_S:
				{
					vector3df P1down = P1node->getPosition();
					P1down.Y += event.KeyInput.Key == KEY_KEY_S ? -5.0f : 5.0f;
					P1node->setPosition(P1down);
					break;
				}

			return true;
			}
		}

		return false;
	}
}; 
And the part where I use it

Code: Select all

int main()
{
	
	//create a receiver out of MyEventReceiver
	MyEventReceiver receiver;

	// create OpenGL device with receiver as the Event Receiver
	IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16, false, false, false, &receiver);
.........other code
Thanks
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post by twilight17 »

Wait I've found Rogerborg's stuff about smooth input here:
http://irrlicht.sourceforge.net/phpBB2/ ... ooth+input

I'll try it out
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
twilight17
Posts: 362
Joined: Sun Dec 16, 2007 9:25 pm

Post by twilight17 »

W00t it works great! Thanks Rogerborg!!! :D :D :D :mrgreen:
Post this userbar I made on other websites to show your support for Irrlicht!
Image
http://img147.imageshack.us/img147/1261 ... wernq4.png
Post Reply