Page 1 of 1

KeyEventReceiver equals true from execution.

Posted: Mon Jan 09, 2012 3:05 pm
by TJBaldy
As the topic states.. My event receiver equals true from the start. Originally this created a problem with movement code I had. But I decided to leave this out as it wasn't too important.

And now I need some Key Presses for things like exit the screen and switching between two different cameras.

Heres my EventReceiver code.. (Mostly created from the terrain tutorial).

Code: Select all

class MyEventReceiver : public IEventReceiver
{
public:
 
 
        MyEventReceiver(scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) :
                Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true)
        {
                Skybox->setVisible(true);
                Skydome->setVisible(false);
        }
 
                                
 
                                
       // This is the one method that we have to implement
        virtual bool OnEvent(const SEvent& event)
        {
                // Remember whether each key is down or up
                if (event.EventType == irr::EET_KEY_INPUT_EVENT)
                        KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
                return false;
        }
 
                /*// 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);
                                Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false);
                                return true;
                        case irr::KEY_KEY_P: // switch wire frame mode
                                Terrain->setMaterialFlag(video::EMF_POINTCLOUD,
                                                !Terrain->getMaterial(0).PointCloud);
                                Terrain->setMaterialFlag(video::EMF_WIREFRAME, false);
                                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;
                        case irr::KEY_KEY_S: // toggle skies
                                showBox=!showBox;
                                Skybox->setVisible(showBox);
                                Skydome->setVisible(!showBox);
                                return true;
                        default:
                                break;
                        }
                }*/
 
              //  return false;
       // }
                
        // This is used to check whether a key is being held down
        virtual bool IsKeyDown(EKEY_CODE keyCode) const
        {
                return KeyIsDown[keyCode];
        }
 
                MyEventReceiver()
        {
                for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
                        KeyIsDown[i] = false;
        }
 
private:
                bool KeyIsDown[KEY_KEY_CODES_COUNT];
        scene::ISceneNode* Terrain;
        scene::ISceneNode* Skybox;
        scene::ISceneNode* Skydome;
        bool showBox;
};
I'm sure someone more experienced than me could point out the issue straight away. I don't know whether it's because I'm using the same event receiver as the one linked with the terrain, skybox, etc?

Thanks :D

Re: KeyEventReceiver equals true from execution.

Posted: Mon Jan 09, 2012 3:21 pm
by randomMesh
You have two contructors but you only set all the keys to false in the default constructor. Do you actually use this constructor?