In HelloWorldScene. declare class HelloWorld: public cocos2d: CCLayer {public :...... CCPoint convertToGL (CCSet * pTouches); virtual void ccTouchesMoved (CCSet * pTouches, CCEvent * event); private: CCSprite * m_pSprite;}; In HelloWorldScene. make the following declaration in cpp // on "init" you need to initialize your instancebool HelloWorld: init () {bool bRet = false; do {CC_BREAK_IF (! CCLayer: init ());...... // MYCode m_pSprite = CCSprite: create ("luffy.png"); // CCSize size = CCDirector: shareddire()-> getWinSize (); // note m_pSprite-> setPosition (ccp (size. width/2, size. height/2); this-> addChild (m_pSprite, 1); // note this-> setTouchEnabled (true); bRet = true;} while (0 ); return bRet;} CCPoint HelloWorld: convertToGL (CCSet * pTouches) {if (pTouches) {CCSetIterator it = pTouche S-> begin (); CCTouch * touch = (CCTouch *) (* it); CCPoint m_tBeginPos = touch-> locationInView (); m_tBeginPos = CCDirector: shareddire () -> convertToGL (m_tBeginPos); return m_tBeginPos;} assert ("pTouches is NULL");} void HelloWorld: ccTouchesMoved (CCSet * pTouches, CCEvent * event) {CCPoint touch_pos = convertToGL (pTouches); CCPoint cur_pos = m_pSprite-> getPosition (); if (ccpDistance (touch_pos, cur_pos )! = 0) {int dx = touch_pos.x-cur_pos.x; int dy = touch_pos.y-cur_pos.y; CCPoint vector = CCPoint: CCPoint (dx, dy ); double dist = sqrt (dx * dx + dy * 1.0); // note CCPoint unit_vector = CCPoint: CCPoint (dx/dist, dy/dist ); int speed = 1; m_pSprite-> setPosition (ccp (cur_pos.x + unit_vector.x * speed, cur_pos.y + unit_vector.y * speed ));}} the effect implemented by the program is that sprite will move closer to the location of the mouse at the specified speed