Page 1 of 1

Stupid question??? Please help

Posted: Wed Jan 31, 2007 8:15 am
by neppyweb
I have this in declaration
private:
scene::ISceneNode* Terrain;

public:
/* MyEventReceiver(scene::ISceneNode* terrain)
{
// store pointer to terrain so we can change its drawing mode
Terrain = terrain;
}*/
This is for use key to move character
virtual bool OnEvent(SEvent event)
{
// check if user presses the key 'W' or 'D'
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
{
switch (event.KeyInput.Key)
{
case irr::KEY_KEY_W: // switch wire frame mode
Terrain->setMaterialFlag(video::EMF_WIREFRAME, !Terrain->getMaterial(0).Wireframe);
return true;
case irr::KEY_KEY_D: // toggle detail map
Terrain->setMaterialType(
Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
video::EMT_DETAIL_MAP : video::EMT_SOLID);
return true;
}
}
}
I have this code in subroutine
/*MyEventReceiver receiver(terrain);
device->setEventReceiver(&receiver);*/
I have this in main function
MyEventReceiver receiver;
device->setEventReceiver(&receiver);

This program can run
1. to menu and then click the "new game" button (as tutorial 5) to call subroutine (to go to game) but I can't use any buttons to move.

What is different from above code?? Because I have them in my program and the error is occured If I do not comment first and second???

So I want to know what it mean???What should I do???

Re: Stupid question??? Please help

Posted: Wed Jan 31, 2007 5:01 pm
by omar shaaban
I have this in main function
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
well i think the error is coming bec u cant add the receiver to the terrain u must added in the create device:

Code: Select all

IrrlichtDevice *device =createDevice(EDT_DIRECT3D9, dimension2d<s32>(800, 600), 16,false, false, false, &receiver);
i think so :roll:

Posted: Wed Jan 31, 2007 5:02 pm
by vitek
Your event receiver must return false if it doesn't handle the event that is coming in. You should put a return false; as the last line in your OnEvent() function.

Travis

Posted: Wed Jan 31, 2007 5:07 pm
by omar shaaban
oops sorry for the wrong answer!!!