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