cocos2d-x-3.x Touch Feedback (3) Event delivery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.