10.COCOS2DX C + + adds touch event listener to Sprite

Source: Internet
Author: User
Tags event listener

1. First header file defines function prototypes for event handling

1 Private : 2     bool Ontouchbegan (touch* ttouch,event* eevent); // Finger Press the event 3     void ontouchmoved (touch* ttouch,event* eevent); // Finger Move Event 4     void ontouchended (touch* ttouch,event* eevent); // Finger Leave event

2. Implementing prototypes

1 BOOLShopitem::ontouchbegan (touch* ttouch,event*eevent) {2    if(Sprite->getboundingbox (). Containspoint (Ttouch->getlocation ())) {//determine if the touch point is within the target range3  4       /** Here is the event content **/5       return true;6}Else7       return false;8 }9 }Ten   One voidShopitem::ontouchmoved (touch* ttouch,event*eevent) { A     /** Here is the event content **/ - } -   the voidshopitem::ontouchended (touch* ttouch,event*eevent) { -     /** Here is the event content **/ -}

3. Binding Events

1     Auto Listener = eventlistenertouchonebyone::create (); 2      This ); 3      This ); 4      This ); 5     This->geteventdispatcher ()->addeventlistenerwithscenegraphpriority (Listener, Sprite);

  

10.COCOS2DX C + + adds touch event listener to Sprite

Related Article

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.