cocos2dx 屏幕触摸

进行屏幕触摸设置时候是在layer层之中进行设计


单点触摸:


auto listener = EventListenerTouchOneByOne::create();//声明事件

listener->onTouchBegan = [](Touch* touch,Event* event);

listener->onTouchMoved = [](Touch* touch,Event* event);

listener->onTouchEnded = [](Touch* touch,Event* event);

_eventDispatcher->addEventListenerWithSceneGraph(listener,this);//注册进入列表


根据touch可以获得触摸点(注意坐标的转换)

Directer::getinstance()->converttoGL(touch->getlocationInveiw());


根据Event可以获取当前注册对象


auto target=static_cast<sprite*>(event->getcurrenttarget());


listenner->setswallowtoches(true);

吞并触摸


你可能感兴趣的:(listener,touch,target,create)