Cocos2d-x 3.x Touch Event

Source: Internet
Author: User

HelloWorldScene.h

bool Touchbegan (Cocos2d::touch*touch, cocos2d::event*Event); // touch Start, return bool type    void touchmoved (Cocos2d::touch*touch, cocos2d::event*Event);     void touchended (Cocos2d::touch*touch, cocos2d::event*Event);     void touchcancelled (Cocos2d::touch*touch, cocos2d::event*Event);

HelloWorldScene.cpp

Eventlistenertouchonebyone*listener=eventlistenertouchonebyone::create (); Listener->ontouchbegan=cc_callback_2 (Helloworld::touchbegan, This);//touch Start, must be added, do not use also to add, otherwise run does not passListener->ontouchmoved=cc_callback_2 (helloworld::touchmoved, This);//Touch MoveListener->ontouchended=cc_callback_2 (helloworld::touchended, This);//touch interrupts, usually system-level messages, the Tathagata phone, touch events will be interruptedListener->ontouchcancelled=cc_callback_2 (helloworld::touchcancelled, This); _eventdispatcher->addeventlistenerwithscenegraphpriority (Listener, This);BOOLHelloworld::touchbegan (Touch*touch, event*Event) {Vec2 pos=touch->getLocation (); Log ("Touchbegan x:%f,y:%f", POS.X,POS.Y); return true;//when returned false, touch move, touch end does not trigger}voidHelloworld::touchmoved (Touch*touch, event*Event) {Vec2 pos=touch->getLocation (); Log ("touchmoved x:%f,y:%f", POS.X,POS.Y);}voidHelloworld::touchended (Touch*touch, event*Event) {Vec2 pos=touch->getLocation (); Log ("touchended x:%f,y:%f", POS.X,POS.Y);}voidHelloworld::touchcancelled (Touch*touch, event*Event) {Vec2 pos=touch->getLocation (); Log ("touchcancelled x:%f,y:%f", POS.X,POS.Y);}

Cocos2d-x 3.x Touch Event

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.