头文件:
#include "base/CCEventListenerController.h"
#include "base/CCController.h"
代码:
auto label = LabelTTF::create("NULL","Courier",40);
label->setPosition(visibleSize / 2);
this->addChild(label);
auto listener = EventListenerController::create(); //控制器事件
listener->onKeyDown = [label](Controller* clr,int keyCode,Event* event){
label->setString(StringUtils::format("%d",keyCode));
};
listener->onKeyRepeat = [label](Controller* clr,keyCode));
};
listener->onKeyUp = [label](Controller* clr,keyCode));
};
Director::getInstance()->getEventDispatcher()
->addEventListenerWithSceneGraPHPriority(listener,this);
Controller::startDiscoveryController(); //发现控制器