cocos2d键盘监听如何实现

cocos2d键盘监听如何实现,第1张

auto listener = EventListenerKeyboard ::create ()

listener ->onKeyReleased = []( EventKeyboard ::KeyCode keyCode , Event * event ){

log ("KeyRelease:%d"槐哗 , keyCode )/余喊/TODO对各按键处理竖明野

}

_eventDispatcher ->addEventListenerWithSceneGraphPriority ( listener, this )

auto keyListener = EventListenerKeyboard::create()

keyListener->setEnabled(true)

keyListener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this)

keyListener->onKeyPressed = CC_CALLBACK_2(HelloWorld::onKeyPressed, this)

_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this)

void HelloWorld:: onKeyPressed(EventKeyboard::KeyCode keyCode, Event* unused_event) //闹册键盘按下

{

cout<<"keyevent"

}

void HelloWorld::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* unused_event) //键盘被释放

{

//cout<<&keyCode<早喊<"液睁宏keyevent two"

cout<<"keyevent two"

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12119991.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存