Cocos2D Implementation of Fruit Ninja

Source: Internet
Author: User

Cocos2DImplementationFruit NinjaIn this article, we will introduce the effect of the knife and light in detail.Cocos2DAn Effect in game development. Let's take a look at the details.

Implementation ideas:

√ Obtain the track and number of control points from multi-point touch. Generally, queue is used. The new point is the point at the end of the team. This is represented as point [16].

√ Loop; point and point [I + 1] form a straight line l. Calculate the slope of the straight line and obtain the angle θ from the slope (which can be used to study polar coordinates ), then obtain the normal equation of l (Xcos θ + ysin θ-p = 0 );
Translate the point with the width W (-W) along the normal direction to obtain two moving tracks.
Here, the absolute value of W should be wider in the header, and the tail should be reduced to 0.

Key Algorithms:

 
 
  1. <EM><EM>     
  2. CGPoint pt = ccpSub(p1, p2);    
  3. GLfloat angle = ccpToAngle(pt);         
  4. GLfloat x = sinf(angle) * w;    
  5. GLfloat y = cosf(angle) * w;    
  6. vertex->x = p1.x+x;    
  7. vertex->y = p1.y-y;    
  8.  </EM></EM>  

Source code download: http://www.cocoachina.com/bbs/job.php? Action = download & aid = 17941

Summary:Cocos2DImplementationFruit NinjaThe content of the "Dao guang effect" tutorial is complete. I hope this article will help you!

Related Article

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.