/*
事件监听器
*/
auto listener = EventListenerTouchOneByOne::create();//设置是否独占监听,设置为true的话,底下的触发器会不起作用
listener->setSwallowTouches(true);
//[=]表是外部变量以传值的方式引用([&]是以传地址的方式引用,[=a,&]是除了a传值,其余的传址,以此类推)
//->bool返回类型),mutable决定是否可以修改外部变量的值
//手指按下处理
listener->onTouchBegan = [=](Touch *touch,Event *event)mutable ->bool{
log("touchbegan");
sprite->setPosition(touch->getLocation().x,touch->getLocation().y);
return true;
};
//手指移动处理
listener->onTouchMoved = [](Touch *touch, Event *event)
{
log("moving");
};
//手指离开处理
listener->onTouchEnded = [](Touch *touch,Event *event){
log("touchend");
};
//事件分发
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);