cocos2d-x 3.1.1 学习笔记[13] listen 监听器
文章出自于 http://blog.csdn.net/zhouyunxuan
//创建监听器 auto listen = EventListenerTouchOneByOne::create(); listen->setSwallowTouches(false); listen->onTouchBegan = [](Touch* touch, Event* event){ auto target = static_cast<Sprite*>(event->getCurrentTarget()); if(target->getBoundingBox().containsPoint(touch->getLocation())) { return true; } return false; }; listen->onTouchMoved = [](Touch* touch,Event* event){ // 获取事件所绑定的 target auto target = static_cast<Sprite*>(event->getCurrentTarget()); if (target->getBoundingBox().containsPoint(touch->getLocation())) { target->setPosition(target->getPosition() + touch->getDelta()); } }; listen->onTouchEnded = [=](Touch* touch, Event* event){};