0

我正在努力在 Irrlicht 中对按键进行编程。

我这样创建了一个事件接收器:

class MyEventReceiver : public IEventReceiver
{
    virtual bool OnEvent(const SEvent& event)
    {
        if (event.EventType == irr::EET_KEY_INPUT_EVENT)
        {
            KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
            {
                if (event.EventType == irr::EET_KEY_INPUT_EVENT&&!event.KeyInput.PressedDown)
                    switch(event.KeyInput.Key)
                    {
                        case KEY_KEY_1:
                        case KEY_KEY_2:
                        case KEY_KEY_3:
                    }
                return true;
            }
        }
         return false;
    }

virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
    return KeyIsDown[keyCode];
}

MyEventReceiver()
{
    memset(KeyIsDown, false, sizeof(KeyIsDown));
}

private:
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
};

这一切似乎都是这样工作的。但是,在“while(device->run())”中,我实现了:

if(receiver.IsKeyDown(irr::KEY_KEY_1))
{

}

我的接收器“标识符接收器未定义”出现错误。在我看到的所有示例中,我看到这个接收者变量没有声明,他们声称它有效。我究竟做错了什么?

我正在构建示例项目“LoadIrrFile”(#15)。

计划是为键 1-3 实施武器开关。初始化按键后,我应该能够获取代码。

我正在使用我在这里找到的片段:http: //irrlicht.sourceforge.net/forum//viewtopic.php?p= 143082

如果需要更多信息,这是一个完整的代码段:http: //pastie.org/pastes/8620301/text

4

1 回答 1

0

片段只有一个补丁。 receiver未在您的 main() 中声明。查看http://irrlicht.sourceforge.net/docu/example004.html上的“完整”示例。您的代码缺少一些东西(来自上面链接中的示例):

MyEventReceiver receiver; // declare it
IrrlichtDevice* device = createDevice(driverType,
        core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver); // use it here
于 2014-01-10T12:27:01.640 回答