The book goes back: Today we allow our leading role to launch darts.
The avi version can be conveniently viewed on mobile phones and PCs. (Only around 20 m, download soon): http://pan.baidu.com/s/1ELk78
This-> setTouchEnabled (true); // In the HelloWorld: init function, void HelloWorld: ccTouchesEnded (CCSet * pTouches, CCEvent * pEvent) // touch Event Response Function {CCTouch * touch = (CCTouch *) pTouches-> anyObject (); CCPoint locInView = touch-> getLocationInView (); CCPoint loc = CCDirector :: sharedDirector ()-> convertToGL (locInView); // if (loc. x <= 20) // do not process {return;} CCSize screenSize = CCDirector: sharedDirector ()-> getVisibleSize (); CCSprite * proj = CCSprite :: create(Projectile.png); proj-> setPosition (ccp (20, screenSize. height/2.0); this-> addChild (proj); // create a dart genie double dx = loc. x-20; double dy = loc. y-screenSize. height/2.0; double d = sqrt (dx * dx + dy * dy); // The distance from the touch point to the start point. double D = sqrt (screenSize. width * screenSize. width + screenSize. height * screenSize. height); // The total running distance of double ratio = D/d; double endx = ratio * dx + 20; // The x coordinate of the final point double endy = ratio * dy + screenSize. height/2.0; // The y coordinate of the final vertex CCMoveTo * move = CCMoveTo: create (D/320, ccp (endx, endy); CCCallFuncN * moveFinish = CCCallFuncN :: create (this, callfuncN_selector (HelloWorld: myDefine); CCSequence * actions = CCSequence: create (move, moveFinish, NULL); proj-> runAction (actions );}
Reprinted please indicate the source: http://blog.csdn.net/xingxiliang/article/details/18599871