//创建监听器
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){};