a little "sweet snippet"

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
roninmagus
Posts: 91
Joined: Fri Oct 31, 2003 5:03 am

a little "sweet snippet"

Post by roninmagus »

Howdy.. I'm new to Irrlicht. well, kind of.. I started messing with it at version 0.1, but I had to quit due to real life issues.

I yesterday picked up 0.4, and man am I impressed. It's come a long way.

Anyways, I was reading through the tutorials and I was wondering how to make the program exit when the user presses Escape. This is a simple solution I came up with. Let me know what you think, or if there are any problems!

Code: Select all

class InputQuitOnEscape : public IEventReceiver
{
public:
	InputQuitOnEscape() : IEventReceiver(), device(NULL)
	{
	}
	
	void SetDevice(IrrlichtDevice * d)
	{
		device = d;
	}
	
	virtual bool OnEvent(SEvent event)
	{
		if(device) {
			if(event.EventType == EET_KEY_INPUT_EVENT)  {
				if(event.KeyInput.Key == KEY_ESCAPE) {
					device->closeDevice();


					return true;
				}	
			}
		}

		return false;
	}

private:
	IrrlichtDevice * device;
};

The idea is to create the input receiver, then give it a pointer to the IrrlichtDevice, so it'll be able to close it when escape is pressed.
daveandrews.org - A Christian Programmer's Weblog | Dusty Engine - A Task Engine for Irrlicht
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

Yep, this would work. The way it's done in the TechDemo is almost the same, it just adds the check to perform the action when the user lets go of the ESC key.

Code: Select all

	if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown == false) {
		// user wants to quit.
		device->closeDevice();
	}
Crud, how do I do this again?
Post Reply