The effect of this Demo is that when you click the screen with your mouse on your computer or with your fingers on your mobile phone, the corresponding genie will move to the most recent position. 1. First, we should add the genie to be moved and enable the touch screen response during initialization. to enable touch-screen response, you only need to call a function: [cpp] setTouchEnabled (true); // by default, the CCLayer does not respond to touch-screen events. We can simply look at the implementation of this function as follows: [cpp] void CCLayer: setTouchEnabled (bool bEnabled) {if (m_bTouchEnabled! = BEnabled) {m_bTouchEnabled = bEnabled; if (m_bRunning) {if (bEnabled) // register {this-> registerWithTouchDispatcher ();} else {CCDirector :: shareddire()-> getTouchDispatcher ()-> removeDelegate (this) ;}}ii. Rewrite the CCLayer void ccTouchesEnded (CCSet * pTouches, CCEvent * pEvent) function as follows: [cpp] void MainLayer: ccTouchesEnded (CCSet * pTouches, CCEvent * pEvent) {CCSetIterator it = pTouches-> begin (); // Obtain the most recently clicked object CCTouch * pTouch = (CCTouch *) (* it); CCPoint ptLocation = pTouch-> getLocation (); // obtain the coordinate value CCNode * pSprNode = getChildByTag (kTagSprite); // obtain the pointer of the genie to be moved if (pSprNode! = NULL) {pSprNode-> stopAllActions (); // stop all previous actions pSprNode-> runAction (CCMoveTo: create (1, CCPointMake (ptLocation. x, ptLocation. y); // move to the clicked position} 3. Note: ①. CCSetIterator is an iterator. Its definition is as follows: [cpp] typedef std :: set <CCObject *>: iterator CCSetIterator; ②. The structure of the CCSet class is as follows: [cpp] view plaincopyclass CCSet: public CCObject {public: * *************************** private: std :: set <CCObject *> * m_pSet;} PS: because it is basic learning, no analysis is performed. more exciting content will be available in the future. Please pay attention to my solemn statement as follows: 1. This article is from the CDN blog. http://t.cn/z86WXvT Ii. All Rights Reserved. This statement shall not be removed when any individual or website reposts this article. 3. You shall not modify the article unless explicitly stated.