A complete flow of single-touch events.
1 BOOLHelloworld::init ()2 {3 if( !layer::init ())4 {5 return false;6 }7Size size = Director::getinstance ()->getvisiblesize ();//get valid length8Auto label = Labelttf::create ("Click Me","Courier", -);//Enter text9Label->setposition (Size.width/2, Size.Height/2);//CentralTenAddChild (label);//Adding layers OneAuto listener = eventlistenertouchonebyone::create ();//Creating an event listener, C++11 features AListener->ontouchbegan = [] (Touch *t, Event *e) {//Capturing variables - - if(E->getcurrenttarget ()->getboundingbox (). Containspoint (T->getlocation ())) {//Get the event target, get the bounding area, get the touch point theLog"Ontouchbegan");//Feedback Output - } - return true;//Note that this is changed if the following two events are not triggered if False - }; +listener->ontouchmoved = [] (touch* T, Event *e) {//new listener, move trigger -Log"ontouchmoved"); + }; Alistener->ontouchended = [] (touch* T, Event *e) {//new listener, touch end trigger atLog"Ontouchend"); - }; -Director::getinstance ()->geteventdispatcher () - addeventlistenerwithscenegraphpriority (listener, label); - return true; -}
The effect of this operation is to click on the target output begin, lift the mouse output end, on the screen slide appears a series of moved.
Basically a small complete set of single-touch feedback mechanisms.
cocos2d-x-3.x Touch Feedback (3) Event delivery