Cocos2dx getting started video tutorials (cocos2d-x)-Lesson 2nd

Source: Internet
Author: User

 

 

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.