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