Open Another Device on Button Click

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
Ovidiu
Posts: 4
Joined: Fri Jun 12, 2009 11:46 am
Location: Romania
Contact:

Open Another Device on Button Click

Post by Ovidiu »

I'm new to Irrlicht...I would like to know how to close the current device and open another one when I press a Button.

This is my current class

Code: Select all


class MyEventReceiver : public IEventReceiver
{
public:

	MyEventReceiver(SAppContext & context) : Context(context) { }
	
	bool OnEvent(const SEvent& event)
	{
		if(event.EventType == irr::EET_KEY_INPUT_EVENT){
			keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
			return false;
		}

		else if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = Context.device->getGUIEnvironment();
			
			switch(event.GUIEvent.EventType)
			{
			case EGET_BUTTON_CLICKED:
				switch(id)
				{	
				case 6:
					//HERE CLOSE AND OPEN ANOTHER DEVICE
					return true;
				case 7:
					Context.device->closeDevice();
					return true;

				default:
					return false;
				}
				break;

			default:
				break;
			}
		}

		return false;
	}

private:
	SAppContext & Context;
};
I want to do this to go from the Main Menu to the Game.

Thanks.
opdude
Posts: 3
Joined: Tue May 12, 2009 6:12 pm

Post by opdude »

Not sure why you'd want to reset the device to switch between a main menu and the game. But if you really want to drop the device and open a new one then its really very simple.

You just need to close the device and then to make a new device right after.

Code: Select all

device->closeDevice();
device = irr::createDevice(video::EDT_DIRECT3D9);
Hope that helps :) and that I didn't miss understand. Another way to switch between the main menu and the game is to have each as their own 'State' then you can just switch 'States'.
Moo?
Ovidiu
Posts: 4
Joined: Fri Jun 12, 2009 11:46 am
Location: Romania
Contact:

Post by Ovidiu »

thanks man...

I searched for some State Manager tutorials...but I can't really find a good one...all of them are too old.

Have you anyone?
opdude
Posts: 3
Joined: Tue May 12, 2009 6:12 pm

Post by opdude »

What I did was to look at IrrWizard, which can write out a basic Game Engine for you, it'll give you an idea of how to build and use states :)

Check it out here: http://irrwizard.sourceforge.net/
Moo?
Post Reply