* 如何在 Cocos2d-x v3.6 C++ 收 onTouchBegan 事件
** 增加下列代碼在 cpp init 函數
auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
** 增加下列代碼(函數)在 cpp 檔
bool HelloWorld::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event) { CCLOG("onTouchBegan x = %f, y = %f", touch->getLocation().x, touch->getLocation().y); return true; }
** 增加下列代碼(函數宣告) 在 header 檔
bool onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event);
No comments:
Post a Comment